#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    How to pass `echo t | ` as arg in `subprocess.check_output`


    Hi,

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

    Code:
    res = subprocess.check_output(["svn.exe", "list", "Https://127.0.0.1:443/svn/Repos"], stderr=subprocess.STDOUT)
    when the script is executed, it would ask user to enter an input key,

    Code:
    (R)eject, accept (t)emporarily or accept (p)ermanently?
    In Command prompt, i am able to pass the input key to the process while calling itself with below command and i am able to get the output:

    Code:
    echo t | svn.exe list Https://127.0.0.1:443/svn/Repos
    from python to call the exe, i am not able to pass the "echo t | " in subprocess.check_output function.

    Is there any way to do this.
    Please help.
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,892
    Rep Power
    481
    use shell=True
    unix example:
    subprocess.check_output("echo t | cat", shell=True,stderr=subprocess.STDOUT)
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0
    Originally Posted by b49P23TIvg
    use shell=True
    unix example:
    subprocess.check_output("echo t | cat", shell=True,stderr=subprocess.STDOUT)
    Hi b49P23TIvg,
    Thanks for your input. but that doesnt work for me.
    I resolved the issue by using two subprocesses, and providing the output of the first process as input to second process.

    Code:
    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]

IMN logo majestic logo threadwatch logo seochat tools logo