Alex Rivera | Logout

What to do with "The input line is too long" error message?

Asked 2009-03-25T18:08:42.923
10

I am trying to use os.system() to call another program that takes an input and an output file. The command I use is ~250 characters due to the long folder names.

When I try to call the command, I'm getting an error: The input line is too long.

I'm guessing there's a 255 character limit (its built using a C system call, but I couldn't find the limitations on that either).

I tried changing the directory with os.chdir() to reduce the folder trail lengths, but when I try using os.system() with "..\folder\filename" it apparently can't handle relative path names. Is there any way to get around this limit or get it to recognize relative paths?

Edit
Report

1 Answer

2

You should use subprocess instead of os.system.

subprocess has the advantage of being able to change the directory for you:

import subprocess
my_cwd = r"..\folder\"
my_process = subprocess.Popen(["command name", "option 1", "option 2"], cwd=my_cwd)
my_process.wait() # wait for process to end
if my_process.returncode != 0:
    print "Something went wrong!"

The subprocess module contains some helper functions as well if the above looks a bit verbose.

answered 2009-03-25T18:38:58.123

Your Answer