简体   繁体   中英

Running external program through python terminal

i try to run a program( a stemmer with a tcl file) to read a txt file and save the result into an other txt file. When i run the command through dos-windows terminal it works fine, but when i run this through python terminal with os.system() it returns 1 value and nothing happens.. Here is the code:

>>>import os
>>>os.system('C:\Python27\Lib\site-packages\tclsh.exe -encoding utf-8     C:\Python27\Lib\site-packages\GreekStemmer.tcl in.txt out.txt')
>>>1

I guess '1' means that the command didnt executed succesfully?? And when i run this in dos-terminal it creates the out.txt file with the result.But here not..

Is in.txt in the same directory that you are running your python script from? You may be misinterpreting where the current working directory is from your function call. If not, instead of in.txt give a more specific path.

Also, there is a subprocess module for external executable calls in python.

On my machine the following doesn't work, because the backslashes are not interpretted. They indicate special charachters.

import os
os.system('C:\bin\Tcl\bin\tclsh.exe')

You can add an r before the string

import os
os.system(r'C:\bin\Tcl\bin\tclsh.exe')

or use doubled backslases

import os
os.system('C:\\bin\\Tcl\\bin\\tclsh.exe')

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