我尝试使用os.system()来调用另一个程序,它接受输入和输出文件。我使用的命令是〜250个字符,由于长文件夹名称。
当我尝试调用该命令时,我收到一个错误:输入行太长。
我猜想有一个 255个字符限制(它使用C系统调用构建,我尝试用 os.chdir()更改目录,以减少这个限制。
<文件夹路径长度,但是当我尝试使用 os.system()与.. \folder\filename它显然不能处理相对路径名。有没有办法绕过这个限制或让它识别相对路径?解决方案你应该使用subprocess模块。请参见此小文档,了解如何重写os.system调用以使用子过程。
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?
解决方案You should use the subprocess module instead. See this little doc for how to rewrite os.system calls to use subprocess.
更多推荐
如何处理“输入行太长”错误信息?
发布评论