dimanche 12 avril 2015

Running external command using python 2.7 in Windows

I am a novice user in python and I am having a problem in executing external command with command-line switch (using python 2.7 in Windows 8 64-bit):



lammpsExe = 'C:/Program Files (x86)/LAMMPS 32-bit 20150403/bin/lmp_serial.exe'
os.system(lammpsExe + " -in in.lmps")


It gives the following error message:



'C Program' is not recognized as an internal or external command, operable program or batch file



It seems that os.system cannot understand the string path for lammpsExe. Then I tried subprocess.call and replace '/' with '\\' in the path:



lammpsExe = 'C:\\Program Files\\LAMMPS 64-bit 20150330\\bin\\lmp_serial.exe'
subprocess.call([lammpsExe,'-in in.lmps'], shell=True)


But it still doesn't work as the command prompt gives the following warning:



IndentationError: unexpected indent



I suspect the command-line switch '-in' is the problem. I have tried various combination of ", ', \, and /, and I still get error messages.


Aucun commentaire:

Enregistrer un commentaire