简体   繁体   中英

Keep open a cmd window

I have a python code in a program that opens a cmd window and runs there another program. The code looks like:

os.chdir('C:/Abaqus_JOBS' + JobDir)
os.system('abaqus job=' + JobName + '-3_run_rel2 user=FalseworkNmm41s interactive')

Now everything works but I get an error in the cmd window and next it closes very quickly not letting me see what was the error. How can I prevent this cmd window to close?

Add + " & timeout 15" or + " & pause" to the string you pass to os.system :

os.chdir('C:/Abaqus_JOBS' + JobDir)
os.system('abaqus job=' + JobName + '-3_run_rel2 user=FalseworkNmm41s interactive' + " & timeout 15")

consider using popen ( Difference between subprocess.Popen and os.system ) instead.

只需使用命令“暂停”,它会要求您按一个键继续。

os.chdir('C:/Abaqus_JOBS' + JobDir)
os.system('abaqus job=' + JobName + '-3_run_rel2 user=FalseworkNmm41s interactive')
raw_input("Press Enter...")

All of these work. I prefer the input("press enter"), but at fist I imported time, and added time.sleep(500), which would give me 500 secs to see what's going on. You can put in even more seconds.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM