tags:

views:

47

answers:

2

Hello all - running a python script from within ESRI's ArcMap and it calls another python script (or at least attempts to call it) using the subprocess module. However, the system window that it executes in (DOS window) comes up only very briefly and enough for me to see there is an error but goes away too quickly for me to actually read it and see what the error is!

Does anyone know of a way to "pause" the DOS window or possibly pipe the output of it to a file or something using python?

Here is my code that calls the script that pops up the DOS window and has the error in it:

py_path2="C:\Python25\python.exe" py_script2="C:\DataDownload\PythonScripts\DownloadAdministrative.py" subprocess.call([py_path2, py_script2])

Much appreciated!

Cheers

A: 

Try doing a raw_input() command at the end of your script (it's input() in Python 3). This will pause the script and wait for keyboard input. If the script raises an exception, you will need to catch it and then issue the command.

Also, there are ways to read the stdout and stderr streams of your command, try looking at subprocess.Popen arguments at http://docs.python.org/library/subprocess.html.

Lior
A: 

subprocess.call accepts the same arguments as Popen. See http://docs.python.org/library/subprocess.html

You are especially interested in argument stderr, I think. Perhaps something like that would help:

err = fopen('logfile', 'w')
subprocess.call([py_path2, py_script2], stderr=err)
err.close()

You could do more if you used Popen directly, without wrapping it around in call.

Piotr Kalinowski