python script doesn't work when testcomplete launches from command line
I have a Python script that works sometimes, but not always, depending on how I open TestComplete. Here are the 2 scenarios.
1) Open TestComplete via the shortcut on the taskbar. Works.
2) Open TestComplete via command line or batch file. Does not work.
This is the line that fails:
p = Popen(command, stdout=PIPE, shell=True)
More specifically, there error exists on 'stdout=PIPE'. I am having the script run a windows command and expecting to read the results.
Sample script:
from subprocess import * def main(): p = Popen("notepad.exe", stdout=PIPE, shell=True)
TestComplete is GUI app and does not have its own console. Omitting stdin and stderr parameters in Popen constructor cause errors in some cases, because code in Lib\subprocess.py tries to use console of current process (TestComplete.exe).
Use not None stdin and stderr values. If it is suitable for you, it could be DEVNULL, PIPE, file...
stdin, stdout and stderr specify the executed program’s standard input, standard output and standard error file handles, respectively. Valid values are PIPE, DEVNULL, an existing file descriptor (a positive integer), an existing file object, and None. PIPE indicates that a new pipe to the child should be created. DEVNULL indicates that the special file os.devnull will be used. With the default settings of None, no redirection will occur; the child’s file handles will be inherited from the parent. Additionally, stderr can be STDOUT, which indicates that the stderr data from the applications should be captured into the same file handle as for stdout.
from subprocess import * def main(): p = Popen("notepad.exe", stdout=PIPE, stdin=PIPE, stderr=PIPE, shell=True)