[Tutor] How to interact with the result of subprocess.call()
robertvstepp at gmail.com
Sat Dec 24 20:58:19 EST 2016
On Sat, Dec 24, 2016 at 7:21 PM, Jim Byrnes <jf_byrnes at comcast.net> wrote:
> On 12/24/2016 05:10 PM, Danny Yoo wrote:
>> On Sat, Dec 24, 2016 at 2:40 PM, Jim Byrnes <jf_byrnes at comcast.net> wrote:
>>> subprocess.call(['libreoffice', '/home/jfb/test.ods'])
>>> If I run the above code, libreoffice opens the test.ods spreadsheet then
>>> just sits there. When I close libreoffice the two enter_keys are executed
>>> the terminal that originated the script.
>>> How can I continue to send keystrokes to libreoffice from the script once
>>> has been opened by subprocess.call()?
I was just looking at Alan's response which is probably the way to go,
but having never used the subprocess module to date, I am wondering if
the stdin option of call()might be used to direct the desired
keystrokes to LO? After looking at
"subprocess.call(args, *, stdin=None, stdout=None, stderr=None,
Run the command described by args. Wait for command to complete, then
return the returncode attribute."
from the docs, I wonder if setting "stdin=PIPE" (or does it need to be
"subprocess.PIPE"?) might do what you want? If I am understanding the
docs correctly, this will result in stdin going to the the new process
you created with call(). I don't have time to play with this --
Christmas Eve and all -- but I am curious if it would work.
More information about the Tutor