
[英]7z command in Python 3.6 subprocess.run() on Windows
[英]I want to use the following command in Python script with subprocess.run()
我有 C 程序,该程序在终端中使用此命令执行。 没问题。
./decrypt -k l-1YM9I5A6XDCcTlSIQR4jFTmO77Od9OOtj\235 < encrypted_input_file > decrypted_output_file
我想在 Python 脚本中使用上面的命令,所以我尝试了这个并且没有任何返回。
# import the necessary packages
import subprocess
import argparse
# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-k", "--key", required=True, help= "Encryption Key Value")
ap.add_argument( "-i", "--input", required=True, help= "Input file" )
ap.add_argument("-o", "--output", required=True, help="Output file")
args = vars(ap.parse_args())
subprocess.run(["./decrypt", "-k", args["key"], "<", args["input"], ">", args["output"]])
请帮我解释一下。 谢谢你。
我尝试这种方式并成功获得结果。
import subprocess
import argparse
# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-k", "--key", required=True, help= "Encryption Key Value")
ap.add_argument( "-i", "--input", required=True, help= "Input file" )
ap.add_argument("-o", "--output", required=True, help="Name of output file")
args = vars(ap.parse_args())
key = args["key"]
inputfile = args["input"]
outputfile = '~/Downloads/'+args["output"]+'.hexdump'
bashcmd = ("./decrypt -k "+ key +
" < "+ inputfile + " > "+ outputfile)
#print(bashcmd)
subprocess.run(bashcmd, shell=True)```
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.