如何在python中使用子流程模块
如果我想从Python2.7中调用像terminal(ubuntu)这样的命令,我应该怎么做 所以我想使用nfc mfclassic,它可以在ubuntu的终端中使用…有人可以帮我在python中使用它 我在终端(Ubuntu)中运行这个东西:如何在python中使用子流程模块,python,ubuntu,subprocess,Python,Ubuntu,Subprocess,如果我想从Python2.7中调用像terminal(ubuntu)这样的命令,我应该怎么做 所以我想使用nfc mfclassic,它可以在ubuntu的终端中使用…有人可以帮我在python中使用它 我在终端(Ubuntu)中运行这个东西:nfc-mfr-a-dumptest.mfd 用法:nfc经典MFR | w a | b[] r | w-执行从(r)卡读取或写入(w)卡 a | b-使用a或b键进行操作 -MiFare转储(MFD)用于写入(卡到MFD)或(MFD到卡) -包含键的Mi
nfc-mfr-a-dumptest.mfd
用法:nfc经典MFR | w a | b[]
r | w-执行从(r)卡读取或写入(w)卡
a | b-使用a或b键进行操作
-MiFare转储(MFD)用于写入(卡到MFD)或(MFD到卡)
-包含键的MiFare转储(MFD)(可选)
或:nfc MFX
x-从MFD中提取有效负载(数据块)
-包含所需负载的MiFare转储(MFD)
-将提取有效负载的二进制文件
您可以直接使用子流程,但是有两个非常好的子流程包装器,可以让您的生活更加轻松
我喜欢:
PBS是一个独特的子流程包装器,可以动态地将系统程序映射到Python函数。PBS通过提供Bash的良好特性(简单的命令调用、简单的管道)以及Python的所有功能和灵活性,帮助您用Python编写shell脚本
例如:
import pbs
print pbs.nfc_mfclassic("r", "a", "dumptest.mfd")
如果您想处理迭代应用程序,也许您应该考虑以下内容:
您可以直接使用子流程,但是有两个非常好的子流程包装器可以让您的生活更加轻松 我喜欢: PBS是一个独特的子流程包装器,可以动态地将系统程序映射到Python函数。PBS通过提供Bash的良好特性(简单的命令调用、简单的管道)以及Python的所有功能和灵活性,帮助您用Python编写shell脚本 例如:
import pbs
print pbs.nfc_mfclassic("r", "a", "dumptest.mfd")
如果您想处理迭代应用程序,也许您应该考虑以下内容:
命令正是您在shell cmdline中键入的命令。困难的部分是正确设置命令文本的格式
参考:
命令正是您在shell cmdline中键入的命令。困难的部分是正确设置命令文本的格式
ref:非常感谢,这对我非常有用,对我非常有用
# This connects to the openbsd ftp site and
# downloads the recursive directory listing.
import pexpect
child = pexpect.spawn ('ftp ftp.openbsd.org')
child.expect ('Name .*: ')
child.sendline ('anonymous')
child.expect ('Password:')
child.sendline ('noah@example.com')
child.expect ('ftp> ')
child.sendline ('cd pub')
child.expect('ftp> ')
child.sendline ('get ls-lR.gz')
child.expect('ftp> ')
child.sendline ('bye')
>>> import subprocess
>>> command = raw_input()
nfc-mfclassic r a dumptest.mfd
p = subprocess.Popen(command)