def main():
process1 = subprocess.Popen("111.exe C:\Python27\test\文本.txt -t 20 字符串1 字符串2", shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while True:
line = process1.stdout.readline()
aaa = open("success.txt", "a+")
if not line:
break
print line
aaa.write(line)
aaa.close()
hanshu(line)
def hanshu(line):
if line.startswith('[字符串2]'):
执行一系列操作,此处略...
#print 'copeleted'
if __name__ == '__main__':
main()
目前程序执行,需要在代码里改动字符串1 字符串2的值来执行,现在想改成命令行传参的格式,比如
111.py 字符串1 字符串2来执行
这种的,不知道怎么改。。 大牛求教育
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
sys模块可以直接调用参数
argparse
最简单的就是使用sys模块
还可以使用optparse、argparse等模块
另外这里还有一些其他的命令行模块:Python最佳实践指南