os.system commands in CGI on IIS?
James T. Dennis
jadestar at idiom.com
Sat Dec 29 12:38:12 EST 2001
Daniel Dittmar <daniel at dittmar.net> wrote:
>> if I execute
>> os.system("copy c:\a.txt c:\b.txt")
>> It does not happen when the cgi page is called from a browser.
>> However if the script is run from the command line, it works fine.
Try os.system( r"copy c:\a.txt c:\b.txt" )
... to make that into a *raw* string (one in which a \ is just
a \ and not a special character.
> In this specific case, you could use shutil.copy. In general, console
> applications (like cmd.exe) will not work inside a service or a GUI only
> program. You might try using the popen2 module, which possibly sets up
> stdin and stdout just right such that Windows doesn't need the console
> window. Setting the property 'may interact with desktop' for the IIS
> service might work as well, but you'll get annoying windows flashing
> across the screen.
> Daniel
For this particular example, shutil.copy() is better. For the
general case of passing literal strings, esp. MS-DOS compatible
filespecs with \'s, use raw strings when you can, mind your
escape sequences when you can't.
More information about the Python-list
mailing list