Domanda

I am using python 3.3 and in my code I need something to open cmd.exe with the following arguments and run it. The desired line in cmd.exe should be:

C:\Program Files (x86)\GlobalMapper15>global_mapper.exe script.gms variable

I saw different answers but the most I managed with subprocess.call is to open either cmd.exe, or global_mapper.exe. I did not manage to obtain the line above in cmd.exe.

I tried so far:

#import subprocess
import os
os.system("cmd.exe C:\Program Files (x86)\GlobalMapper15\global_mapper.exe script.gms")
#subprocess.call(["cmd.exe C:\Program Files (x86)\GlobalMapper15\global_mapper.exe", "script.gms"])

Neither of them worked well.

Of course, it would be great if the line would be also executed. Can anyone help me make this happen?

Thank you all,

È stato utile?

Soluzione

To run global_mapper.exe in given directory:

#!/usr/bin/env python
from subprocess import call

dir = r"C:\Program Files (x86)\GlobalMapper15"
cmdline = "global_mapper.exe script.gms variable"
rc = call(cmdline, cwd=dir) # run `cmdline` in `dir`

If you want to start the command in a new console window:

rc = call("start cmd /K " + cmdline, cwd=dir, shell=True)

Altri suggerimenti

maybe with this:

import os
os.system("program.exe -parameter")

you can Create a .bat file and call it

dir = r"C:\Program Files (x86)\GlobalMapper15"
write=''.join((dir,'\\','call.bat'))
f= open(write,'w')
with f:
  f.write('@ECHO ON\n Call global_mapper.exe script.gms variable'
subprocess.call(write,cwd=dir)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top