我有外部脚本(sh),我想做这样的事情:arg1 = some stringarg2 = some string2arg3 = cmd = [/usr/local/bin/myscript, arg1, arg2, arg3]Popen(cmd, shell=False, stdin=PIPE, stdout=PIPE, stderr...

我有外部脚本(sh),我想做这样的事情:
arg1 = 'some string'
arg2 = 'some string2'
arg3 = ''
cmd = ['/usr/local/bin/myscript', 'arg1', 'arg2', 'arg3']
Popen(cmd, shell=False, stdin=PIPE, stdout=PIPE, stderr=PIPE)
我似乎认为,如果“ arg3”为空,则只用两个参数调用了我的脚本,
如果它为空,如何传递“ arg3”事件?
解决方法:
test.py:
import sys
print(sys.argv)
test2.py:
import subprocess
import shlex
cmd="test.py 'some string' 'some string2' '' "
proc=subprocess.Popen(shlex.split(cmd))
运行test2.py产生
['test.py', 'some string', 'some string2', '']
沃梦达教程
本文标题为:python-如何将空参数传递给Popen(shell = False)?


基础教程推荐
猜你喜欢
- Python的函数使用示例详解 2023-08-08
- python猜数字小游戏实现代码 2023-08-04
- Python四大金刚之列表详解 2023-08-04
- python pandas数据处理之删除特定行与列 2022-08-30
- 用Python鉴黄(上) 2023-09-04
- pytorch和tensorflow计算Flops和params的详细过程 2022-08-30
- windows python2下停止,清空,启动tomcat 2023-09-03
- 创建python虚拟环境(在ubuntu16.04中) 2023-09-04
- python线程池/进程池创建 2023-09-04
- 在centos6.4下安装python3.5 2023-09-04