Skip to content Skip to sidebar Skip to footer

How Do I Make A Command To Run In Background Using Pexpect.spawn?

I have a code snippet in which I run a command in background: from sys import stdout,exit import pexpect try: child=pexpect.spawn('./gmapPlayerCore.r &') except:

Solution 1:

You are asking the spawned child to be synchronous so that you can execute child.expect(…) and asynchronous &. These don't agree with each other.

You probably want:

child=pexpect.spawn("./gmapPlayerCore.r") # no &
status=child.expect(["[nN]o [sS]uch [fF]ile","",pexpect.TIMEOUT,pexpect.EOF])
child.interact()

where interact is defined as:

This gives control of the child process to the interactive user (the human at the keyboard). …

Post a Comment for "How Do I Make A Command To Run In Background Using Pexpect.spawn?"