Question

I am having an issue executing a python script from a different python script:

filePath = "C:\Desktop\TestScripts\test.py"
####subprocess.call(filePath, shell = True)

child = subprocess.Popen(filePath, shell=True, stderr=subprocess.PIPE)
   while True:
        out = child.stderr.read(1)
        if out == '' and child.poll() != None:
           break
        if out != '':
           sys.stdout.write(out)
           sys.stdout.flush()

When I execute this, I am getting:

'C:\Desktop\TestScripts\' is not recognized as an internal or external command,
operable program or batch file.

I couldn't interpret the above error. Any suggestions would be highly appreciated.

Était-ce utile?

La solution

Notice that the error is saying that the file 'C:\Desktop\TestScripts\' could not be found. The filename is getting truncated because '\t' is a TAB character.

In [156]: print('C:\Desktop\TestScripts\test.py')
C:\Desktop\TestScripts  est.py

Use the raw string r'C:\Desktop\TestScripts\test.py' instead.

In [157]: print(r'C:\Desktop\TestScripts\test.py')
C:\Desktop\TestScripts\test.py
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top