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

Discussion in 'Python' started by dachakku@gmail.com, Nov 26, 2012.

  1. Guest

    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.
    , Nov 26, 2012
    #1
    1. Advertising

  2. 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
    Kushal Kumaran, Nov 26, 2012
    #2
    1. Advertising

  3. Guest

    On Monday, 26 November 2012 16:22:42 UTC+5:30, Duncan Booth wrote:
    > 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.
    >
    >
    >
    > --
    >
    > Duncan Booth http://kupuguy.blogspot.com


    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.
    , Nov 26, 2012
    #3
  4. Guest

    On Monday, 26 November 2012 16:32:22 UTC+5:30, Kushal Kumaran wrote:
    > 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..
    , Nov 26, 2012
    #4
  5. Guest

    On Monday, 26 November 2012 16:32:22 UTC+5:30, Kushal Kumaran wrote:
    > 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..
    , Nov 26, 2012
    #5
  6. writes:

    > On Monday, 26 November 2012 16:32:22 UTC+5:30, Kushal Kumaran wrote:
    >> 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?

    --
    regards,
    kushal
    Kushal Kumaran, Nov 26, 2012
    #6
  7. Miki Tebeka Guest

    > But i dont know how to pass the "echo t | " in subprocess.check_output while calling a process.
    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.
    Miki Tebeka, Nov 26, 2012
    #7
  8. Guest

    On Monday, 26 November 2012 21:10:02 UTC+5:30, Miki Tebeka wrote:
    > > But i dont know how to pass the "echo t | " in subprocess.check_output while calling a process.

    >
    > 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... :)
    , Nov 28, 2012
    #8
  9. Miki Tebeka Guest

    On Wednesday, November 28, 2012 4:38:35 AM UTC-8, wrote:
    > Thanks.. Creating two subprocesses worked for me. I did the code as below,

    Glad it worked.
    Miki Tebeka, Nov 28, 2012
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tricky
    Replies:
    0
    Views:
    575
    Tricky
    Mar 19, 2009
  2. Tricky
    Replies:
    0
    Views:
    998
    Tricky
    Mar 19, 2009
  3. Guest
    Replies:
    0
    Views:
    99
    Guest
    Jan 4, 2013
  4. Chris Angelico
    Replies:
    0
    Views:
    138
    Chris Angelico
    Jan 4, 2013
  5. Guest
    Replies:
    0
    Views:
    141
    Guest
    Jan 4, 2013
Loading...

Share This Page