Skip to content Skip to sidebar Skip to footer

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,

Solution 1:

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

import osos.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 osos.system('C:\\bin\\Tcl\\bin\\tclsh.exe')

Solution 2:

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.

Post a Comment for "Running External Program Through Python Terminal"