Forum Discussion

ibeard's avatar
ibeard
Occasional Contributor
9 years ago

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 ...
  • Silmaril's avatar
    9 years ago

    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...

    From Popen man:

    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)