简体   繁体   English

如何使用 python 脚本中的多个参数运行 perl 脚本

[英]How to run perl script with multiple args from python script

I made a python code that must sequentially execute a series of perl commands on the PC shell, the problem is that I did not realize that to send these scripts I have to add parameters (i have n_params), advice?我做了一个python代码,必须在PC上依次执行一系列perl命令shell,问题是我没有意识到要发送这些脚本我必须添加参数(建议)

example command to send perl [file_name.pl] [params]发送perl [file_name.pl] [params]的示例命令

To run these commands on the windows CMD I am using os and subprocess要在 windows CMD 上运行这些命令,我正在使用 os 和 subprocess

python code example python 代码示例

# command = perl [file_name.pl] [params]
# path = location/of/where/the/pl/file/is/saved

perl_script = subprocess.Popen(["C:\\Perl64\\bin\\perl.exe",path + command], stdout=sys.stdout)
perl_script.communicate()

But running the script like this, the code gets me wrong because it says it can't find the filename in the specific directory但是像这样运行脚本,代码让我错了,因为它说它在特定目录中找不到文件名

This argument to Popen() Popen()的这个参数

["C:\\Perl64\\bin\\perl.exe", path + command] 

does not look correct since you wrote that command is perl [file_name.pl] [params] .看起来不正确,因为您编写的commandperl [file_name.pl] [params] Instead try:而是尝试:

p = subprocess.Popen(["C:\\Perl64\\bin\\perl.exe", path+"file_name.pl", "param1", "param2", ...])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM