Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Execute function returns stderr for command line file read. #1421

Answered by Byron
joydeba asked this question in Q&A
Discussion options

The command gh auth login --with-token<ghKeysconfig in the terminal works fine.

Here, ghKeysconfig is the file.

But when I use my python script with GitPython as follows

gLocal = git.Git("ansible")
authenticate_gh = gLocal.execute(["gh","auth","login","--with-token","<ghKeysconfig"])

It shows this error -

Cmd('gh') failed due to: exit code(1)
 cmdline: gh auth login --with-token <ghKeysconfig
 stderr: 'accepts 0 arg(s), received 1' 
You must be logged in to vote

It's not easly possible to pass standard input, i.e. the <ghKeysconfig part via the git command in GitPython.

Instead I recommend using a standard Popen call to wire up standard input to pass the contents of the token file to the gh process.

Replies: 1 comment 3 replies

Comment options

It's not easly possible to pass standard input, i.e. the <ghKeysconfig part via the git command in GitPython.

Instead I recommend using a standard Popen call to wire up standard input to pass the contents of the token file to the gh process.

You must be logged in to vote
3 replies
Comment options

Popen did not work as well -

process = subprocess.Popen(["gh","auth","login","--with-token","<ghKeysconfig"], stdout=PIPE, stderr=PIPE, cwd='ansible')
pull_changedFilesOriginal, stderroutput = process.communicate()

It shows
stderroutput = "b'accepts 0 arg(s), received 1\n'"

Comment options

Byron Apr 2, 2022
Maintainer

The call presented here is the same as above and thus doesn't try to pipe the token file gh via stdin. Something like this could work, and if not please consult the documentation of popen on how to pass things via stdin

process = subprocess.Popen(["gh","auth","login","--with-token"], stdin=os.open("ghKeysconfig", "r"), cwd='ansible')
pull_changedFilesOriginal, stderroutput = process.communicate()
Comment options

Yes, a little bit of change working fine for me. Thanks @Byron

process = subprocess.Popen(["gh","auth","login","--with-token"], stdin=open("ghKeysconfig", "r"), cwd='ansible')
pull_changedFilesOriginal, stderroutput = process.communicate() 
Answer selected by Byron
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1420 on April 02, 2022 00:10.

AltStyle によって変換されたページ (->オリジナル) /