I have a command where it should execute in the path which I have given as input in the subprocess. I'm getting the following error when tried to execute it. command = "bazel run //ros/src/bag_to_yaml:bag_to_yaml -- "
command = command + " ".join(tracks_ids)
print(command)
path1 = "/home/terli.vaibhav/development/github.robot.car/cruise/cruise/develop"
p = subprocess.Popen(command, path1 ,bufsize=1, shell = True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)这就是我得到的TypeError错误: bufsize必须是一个整数。
Traceback (most recent call last):
File "example.py", line 45, in <module>
execute_subprocess(output_dir, segment, vai)
File "example.py", line 31, in execute_subprocess
p = subprocess.Popen(command, path1 ,shell = True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
File "/usr/lib/python3.6/subprocess.py", line 629, in __init__
raise TypeError("bufsize must be an integer")
TypeError: bufsize must be an integer发布于 2022-09-09 07:53:22
在使用shell=True时,必须将整个命令行作为第一个参数。第二个论点恰好是bufsize。因此,您的代码将path1作为bufsize传递,您将得到该错误。您可能想要这样做:
cmdline = command + ' ' + path1
p = subprocess.Popen(cmdline,bufsize=1, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)顺便问一下:
shell=True,因为您的代码不使用任何shell特性。这将为nothing.subprocess.check_output而不是Popen从子进程获取输出。因此,我会重写您的代码如下所示:
path1 = "/home/terli.vaibhav/development"
cmdline = ['bazel', 'run', '//ros/src/bag_to_yaml:bag_to_yaml', '--'] + track_ids + [path1]
output = subprocess.check_output(cmdline)https://stackoverflow.com/questions/73658891
复制相似问题