how to pass "echo t | " input to subprocess.check_output() method

D

dachakku

Hi all,

I want to list the repositories in svn using python. For this i have used below command,
" res = subprocess.check_output(["svn.exe", "list", "Https://127.0.0.1:443/svn/Repos"], stderr=subprocess.STDOUT) "

but it throws an exception, since it requires an user input to validate certificate,
" (R)eject, accept (t)emporarily or accept (p)ermanently? "

from Command prompt im able to pass the input while calling the process, and im able to get the output

"echo t | svn list Https://127.0.0.1:443/svn/Repos"

But i dont know how to pass the "echo t | " in subprocess.check_output while calling a process.
Is there a way to do this?
Please help.
 
K

Kushal Kumaran

Hi all,

I want to list the repositories in svn using python. For this i have used below command,
" res = subprocess.check_output(["svn.exe", "list", "Https://127.0.0.1:443/svn/Repos"], stderr=subprocess.STDOUT) "

but it throws an exception, since it requires an user input to validate certificate,
" (R)eject, accept (t)emporarily or accept (p)ermanently? "

from Command prompt im able to pass the input while calling the process, and im able to get the output

"echo t | svn list Https://127.0.0.1:443/svn/Repos"

But i dont know how to pass the "echo t | " in subprocess.check_output while calling a process.
Is there a way to do this?
Please help.


You could pass in a stdin argument to subprocess.check_output with a
value of 't\n'.

However, you might want to use something like http://pysvn.tigris.org/,
which is a python library for accessing subversion repositories.
 
D

dachakku

(e-mail address removed) wrote:


Hi all,

I want to list the repositories in svn using python. For this i have
used below command, " res = subprocess.check_output(["svn.exe",
"list", "Https://127.0.0.1:443/svn/Repos"], stderr=subprocess.STDOUT)

but it throws an exception, since it requires an user input to
validate certificate, " (R)eject, accept (t)emporarily or accept
(p)ermanently? "

from Command prompt im able to pass the input while calling the
process, and im able to get the output

"echo t | svn list Https://127.0.0.1:443/svn/Repos"

But i dont know how to pass the "echo t | " in subprocess.check_output
while calling a process. Is there a way to do this?
Please help.



Run svn once manually as the same user that is running your script then

when you get the prompt verify that it is indeed the certificate and

accept it permanently. That will allow your script to work proviuded the

certificate doesn't change.



Also, change the command you run to include the --non-interactive

command line option so that if the certificate ever does change in the

future the command will fail rather than prompting.



Alternatively use --non-interactive --trust-server-cert to just accept

any old server regardless what certificate it uses, but be aware that

this impacts security.

Hi Duncan,

I tried using --non-interactive --trust-server-cert, but the call fails with error message,
svn: E175002: OPTIONS of 'https://127.0.0.1/svn/Repos': Server certificate verification failed: certificate issued for a different hostname, issuer is not trusted (https://127.0.0.1)

that's why I want to pass an input to accept the certificate (t)emporarily or (p)ermanently.
 
D

dachakku

(e-mail address removed) writes:


Hi all,

I want to list the repositories in svn using python. For this i have used below command,
" res = subprocess.check_output(["svn.exe", "list", "Https://127.0.0.1:443/svn/Repos"], stderr=subprocess.STDOUT) "
but it throws an exception, since it requires an user input to validate certificate,
" (R)eject, accept (t)emporarily or accept (p)ermanently? "

from Command prompt im able to pass the input while calling the process, and im able to get the output

"echo t | svn list Https://127.0.0.1:443/svn/Repos"

But i dont know how to pass the "echo t | " in subprocess.check_output while calling a process.
Is there a way to do this?
Please help.





You could pass in a stdin argument to subprocess.check_output with a

value of 't\n'.



However, you might want to use something like http://pysvn.tigris.org/,

which is a python library for accessing subversion repositories.



--

regards,

kushal

Hi Kushal,

I tried passing the value 't\n' to check_output. But I think we cannot pass a string to stdin.

When I tried the below command,
subprocess.check_output([svn, "list", repos_Url], stdin='t\n', stderr=subprocess.STDOUT)

I got the below error message,
File "C:\Python27\lib\subprocess.py", line 786, in _get_handles
p2cread = msvcrt.get_osfhandle(stdin.fileno())
AttributeError: 'str' object has no attribute 'fileno'

could you tell me how to pass the value to stdin..
 
D

dachakku

(e-mail address removed) writes:


Hi all,

I want to list the repositories in svn using python. For this i have used below command,
" res = subprocess.check_output(["svn.exe", "list", "Https://127.0.0.1:443/svn/Repos"], stderr=subprocess.STDOUT) "
but it throws an exception, since it requires an user input to validate certificate,
" (R)eject, accept (t)emporarily or accept (p)ermanently? "

from Command prompt im able to pass the input while calling the process, and im able to get the output

"echo t | svn list Https://127.0.0.1:443/svn/Repos"

But i dont know how to pass the "echo t | " in subprocess.check_output while calling a process.
Is there a way to do this?
Please help.





You could pass in a stdin argument to subprocess.check_output with a

value of 't\n'.



However, you might want to use something like http://pysvn.tigris.org/,

which is a python library for accessing subversion repositories.



--

regards,

kushal

Hi Kushal,

I tried passing the value 't\n' to check_output. But I think we cannot pass a string to stdin.

When I tried the below command,
subprocess.check_output([svn, "list", repos_Url], stdin='t\n', stderr=subprocess.STDOUT)

I got the below error message,
File "C:\Python27\lib\subprocess.py", line 786, in _get_handles
p2cread = msvcrt.get_osfhandle(stdin.fileno())
AttributeError: 'str' object has no attribute 'fileno'

could you tell me how to pass the value to stdin..
 
K

Kushal Kumaran

(e-mail address removed) writes:


Hi all,

I want to list the repositories in svn using python. For this i have used below command,
" res = subprocess.check_output(["svn.exe", "list", "Https://127.0.0.1:443/svn/Repos"], stderr=subprocess.STDOUT) "
but it throws an exception, since it requires an user input to validate certificate,
" (R)eject, accept (t)emporarily or accept (p)ermanently? "

from Command prompt im able to pass the input while calling the process, and im able to get the output

"echo t | svn list Https://127.0.0.1:443/svn/Repos"

But i dont know how to pass the "echo t | " in subprocess.check_output while calling a process.
Is there a way to do this?
Please help.





You could pass in a stdin argument to subprocess.check_output with a

value of 't\n'.



However, you might want to use something like http://pysvn.tigris.org/,

which is a python library for accessing subversion repositories.

Hi Kushal,

I tried passing the value 't\n' to check_output. But I think we cannot pass a string to stdin.

When I tried the below command,
subprocess.check_output([svn, "list", repos_Url], stdin='t\n', stderr=subprocess.STDOUT)

I got the below error message,
File "C:\Python27\lib\subprocess.py", line 786, in _get_handles
p2cread = msvcrt.get_osfhandle(stdin.fileno())
AttributeError: 'str' object has no attribute 'fileno'

could you tell me how to pass the value to stdin..

Follow Chris Rebert's suggestion to use subprocess.Popen and the
communicate method of the Popen object.

Have you taken a look at pysvn?
 
D

dachakku

You need to create two subprocess and connect the stdout of the first to the stdin of the 2'nd.



See http://pythonwise.blogspot.com/2008/08/pipe.html for a possible solution.

Hi Miki,
Thanks.. Creating two subprocesses worked for me. I did the code as below,

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]

Thanks again... :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top