The problem could be in the way you are passing arguments to subprocess.call
(问题可能在于您将参数传递给subprocess.call的方式)
The function's signature is
(该函数的签名是)
subprocess.call(args, *, stdin=None, stdout=None, stderr=None, shell=False, cwd=None, timeout=None)
From documentation :
(从文档 :)
args is required for all calls and should be a string, or a sequence of program arguments.
(args是所有调用所必需的,并且应为字符串或程序参数序列。)
Providing a sequence of arguments is generally preferred, as it allows the module to take care of any required escaping and quoting of arguments (eg to permit spaces in file names). (通常最好提供一个参数序列,因为它允许模块处理任何必需的参数转义和引用(例如,允许在文件名中保留空格)。)
If passing a single string, either shell must be True (see below) or else the string must simply name the program to be executed without specifying any arguments. (如果传递单个字符串,则外壳程序必须为True(请参见下文),否则该字符串必须简单地命名要执行的程序而无需指定任何参数。)
So your code should be something like this:
(因此,您的代码应如下所示:)
Output = subprocess.call(["bin/sudo", "-u", "username", "/bin/PHP", "pathtofilename.php", "V1", "V2"])
Alternatively it could be
(或者,它可能是)
Output = subprocess.call(["bin/sudo -u username /bin/PHP pathtofilename.php V1 V2"], shell=True)
but you should consider possible security issues .
(但是您应该考虑可能的安全问题 。)
Note: If you are on Python 3.5+ consider using subprocess.run , especially if you want to capture stdout or stderr with a CompletedProcess instance.
(注意:如果您使用的是Python 3.5+,请考虑使用subprocess.run ,尤其是当您想使用CompletedProcess实例捕获stdout或stderr时。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…