简体   繁体   English

python模块中的Linux脚本

[英]Linux script in a python module

I'm doing a project on automation and we are using the MFRC522 library, but some of our equipment isn't working as intended. 我正在做一个关于自动化的项目,我们正在使用MFRC522库,但是我们的某些设备无法正常工作。 This has led us on an awkward detour for scripting and such. 这导致我们在脚本编写等方面走了尴尬的弯路。 We are able to get the UID's of the NFC tag, and now we want to create a linux script that will reference these numbers. 我们能够获得NFC标签的UID,现在我们要创建一个引用这些数字的linux脚本。

The long and short of it is: is it possible to make a linux script run from a python module? 它的长短是:是否可以从python模块运行linux脚本?

ex: 例如:

if status == MIFAREReader.MI_OK:
   print "Card read UID:" +str(backData[0])+ "," + \
          str(backData[1]) +"," + str(backData[2])  + \
           ","+str(backData[3])+","+str(backData[4])

here is where I put the code for getting the UID to the file 这是我将代码获取UID的位置

here is where I'd like to put the code to link the linux script 这是我想放置代码以链接linux脚本的地方

Maybe you could use the subprocess module. 也许您可以使用子流程模块。 You can do things like this: 您可以执行以下操作:

import subprocess
subprocess.call('ls | wc -l', shell=True)

Important to note that using the shell flag presents some security concerns. 重要的是要注意,使用shell标志会带来一些安全问题。 That's in the docs linked above. 在上面链接的文档中。

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

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