2

check_call ステートメントを subprocess.Popen に変換しているときに、以下のエラーが発生しました。"&&" を台無しにしていると思います。修正方法について誰か助けてもらえますか?

check_call("git fetch ssh://username@company.com:29418/platform/vendor/company-proprietary/radio %s && git cherry-pick FETCH_HEAD" % change_ref , shell=True)
proc = subprocess.Popen(['git', 'fetch', 'ssh://username@company.com:29418/platform/vendor/company-proprietary/radio', change_ref , '&& git' , 'cherry-pick', 'FETCH_HEAD'], stderr=subprocess.PIPE)

Error:-

fatal: Invalid refspec '&& git
4

2 に答える 2

1

&&シェル機能です。コマンドを個別に実行します。

proc = subprocess.Popen(['git', 'fetch', 'ssh://username@company.com:29418/platform/vendor/company-proprietary/radio', change_ref], stderr=subprocess.PIPE)
out, err = proc.communicate()  # Wait for completion, capture stderr

# Optional: test if there were no errors
if not proc.returncode:
    proc = subprocess.Popen(['git' , 'cherry-pick', 'FETCH_HEAD'], stderr=subprocess.PIPE)
    out, err = proc.communicate()
于 2012-12-29T19:53:23.047 に答える
1
rc = Popen("cmd1 && cmd2", shell=True).wait()
if rc != 0:
   raise Error(rc)

または

rc = Popen(["git", "fetch", "ssh://...", change_ref]).wait()
if rc != 0:
   raise Error("git fetch failed: %d" % rc)
rc = Popen("git cherry-pick FETCH_HEAD".split()).wait()
if rc != 0:
   raise Error("git cherry-pick failed: %d" % rc)

キャプチャするにはstderr

proc_fetch = Popen(["git", "fetch", "ssh://...", change_ref], stderr=PIPE)
stderr = proc_fetch.communicate()[1]
if p.returncode == 0: # success
   p = Popen("git cherry-pick FETCH_HEAD".split(), stderr=PIPE)
   stderr = p.communicate()[1]
   if p.returncode != 0: # cherry-pick failed
      # handle stderr here
      ...
else: # fetch failed
    # handle stderr here
    ...
于 2012-12-29T19:56:28.620 に答える