Home > Net >  Passing command to the called script
Passing command to the called script

Time:12-28

I would like to call a script named openseessp and then pass "source test.tcl" argument to this script.

I tried with subprocess module but after it invoked openseessp it exits and then runs source test.tcl command. I need to run this without exiting the first (openseessp):

subprocess.run(['openseessp', 'source test.tcl'], shell=True, cwd=directoryJob)

CodePudding user response:

From the docs:

args is required for all calls and should be a string, or a sequence of program arguments. Providing a sequence of arguments is generally preferred, as it allows the module to take care of any required escaping and quoting of arguments (e.g. to permit spaces in file names). If passing a single string, either shell must be True (see below) or else the string must simply name the program to be executed without specifying any arguments.

That is, either pass a string with shell=True,

subprocess.run('openseessp source test.tcl', shell=True, cwd=directoryJob)

or pass a list (shell is False by default).

subprocess.run(['openseessp', 'source test.tcl'], cwd=directoryJob)
  • Related