To pass `echo t | `as arg in` subprocess.check_output`

I am new to Python. I ran into a problem below.

I called exe using subprocess.check_output from my python script.

res = subprocess.check_output(["svn.exe", "list", "Https://127.0.0.1:443/svn/Repos"], stderr=subprocess.STDOUT) 

when the script is executed on the command line, I get a prompt to enter input,

 (R)eject, accept (t)emporarily or accept (p)ermanently? 

But when I execute the script from the batch file, I do not receive this message, and by default the check_output call fails.
Is there any way to pass input during subprocess.check_output call so that I can run the script in batch mode.

Hi, I am updating my question: I tried to start svn from the command line with the following command:

 echo t | svn.exe list Https://127.0.0.1:443/svn/Repos 

I got the result without user input.

But I could not pass echo t | in subprocess.check_output . Is there any way to do this?

Please help me solve this problem. Thanks

+4
source share
3 answers

I found two solutions for my problem,

1.Get this soul from this link http://desipenguin.com/techblog/2009/01/13/fun-with-python-subprocessstdin/

 proc = subprocess.Popen((["svn.exe", "list", "Https://127.0.0.1:443/svn/Repos"], stdin=subprocess.PIPE, stdout=subprocess.PIPE) print proc.communicate('t\n')[0] 

This allowed the provision of key input 't' into the process. But I could not read the result. So, I followed the second solution.

2. The use of two subprocesses:

 p = subprocess.Popen("echo t |", shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) p1 = subprocess.Popen(["svn.exe", "list", "Https://127.0.0.1:443/svn/Repos"], shell=True, **stdin=p.stdout**, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() output = p1[0] 

Here, the output of process 1 is set as the input of process 2. Thus, this is equal to echo t | svnmucc mkdir d:\temp echo t | svnmucc mkdir d:\temp .

Thanks.

0
source

I think this is not the answer to the question in the header, but did you try to start svn with --non-interactive --trust-server-cert ? Isn't that what you want?

+1
source

The message you receive is related to certificates. Therefore, instead of adding complexity to transferring input to the command, either fix the certificate problem or pass the --trust-server-cert flag to the SVN command.

 res = subprocess.check_output(["svn.exe", "--trust-server-cert", "list", "url"], stderr=subprocess.STDOUT) 
+1
source

Source: https://habr.com/ru/post/1447734/


All Articles