在python中将变量传入命令
我正在编写一个python脚本来执行shell命令,我正在获取参数,并希望将该参数的值传递给命令在python中将变量传入命令,python,freeswitch,Python,Freeswitch,我正在编写一个python脚本来执行shell命令,我正在获取参数,并希望将该参数的值传递给命令 #!/usr/bin/env python import commands import subprocess import sys command = commands.getoutput('fs_cli -x "sofia profile external restart"') 这个代码很好用 当我尝试接受参数并传递到命令时,它失败了 command=commands.getoutput(
#!/usr/bin/env python
import commands
import subprocess
import sys
command = commands.getoutput('fs_cli -x "sofia profile external restart"')
这个代码很好用
当我尝试接受参数并传递到命令时,它失败了
command=commands.getoutput('fs_cli-x“sofia profile”+sys.argv[1]
+“重新启动”)
支持人员您应该写:
command = commands.getoutput('fs_cli -x "sofia profile ' + sys.argv[1] + ' restart"')
查看和。其中一种方法是将要执行的命令转换为字符串,然后作为eval()执行 例如: eval(字符串中的表达式/命令)