用于执行重复脚本输入的Python脚本

用于执行重复脚本输入的Python脚本,python,shell,input,terminal,Python,Shell,Input,Terminal,我有一个脚本,它需要使用相同的输入执行多次(9次),以寻找一个简化过程的解决方案 我的脚本和操作的标准命令是: steghide extract -sf file.jpg p/s:我在Linux上运行您有: 程序(python脚本) N(9)个与程序一起处理的文件 程序的1个参数(输入) 现在,您想从命令行为具有相同参数的N(9)个文件运行脚本,对吗 我的建议是编写另一个脚本,为具有相同输入参数的N个文件运行脚本 系统命令行参数的基本介绍: # Module sys has to be imp

我有一个脚本,它需要使用相同的输入执行多次(9次),以寻找一个简化过程的解决方案

我的脚本和操作的标准命令是:

steghide extract -sf file.jpg
p/s:我在Linux上运行

您有:

  • 程序(python脚本)
  • N(9)个与程序一起处理的文件
  • 程序的1个参数(输入)
  • 现在,您想从命令行为具有相同参数的N(9)个文件运行脚本,对吗

    我的建议是编写另一个脚本,为具有相同输入参数的N个文件运行脚本

    系统命令行参数的基本介绍:

    # Module sys has to be imported:
    import sys                
    
    # Iteration over all arguments:
    for eachArg in sys.argv:   
        print(eachArg)
    
    此脚本的示例调用:

    python argumente.py python course for beginners
    
    输出:

    argumente.py
    python
    course
    for
    beginners
    
    现在我们可以根据您的情况修改这个简单的示例。首先,创建一个新的python程序并导入python脚本,假设您的python程序名为
    my_prog1.py

    import my_prog1
    import os
    import sys
    
    var = sys.argv[1]
    
    os.system('python my_prog1 file1_location' var)
    os.system('python my_prog1 file2_location' var)
    os.system('python my_prog1 file3_location' var)
    os.system('python my_prog1 file4_location' var)
    os.system('python my_prog1 file5_location' var)
    os.system('python my_prog1 file6_location' var)
    os.system('python my_prog1 file7_location' var)
    os.system('python my_prog1 file8_location' var)
    os.system('python my_prog1 file9_location' var)
    
    对该脚本的调用位置(让我们将该脚本命名为sample.py):

    现在它将获得相同的输入并运行N个文件

    [讨论后更新答案]

    因为提问者使用的是带命令的steghide,每次都需要输入密码短语。从中,可以向命令添加密码短语参数

    import os
    import sys
    
    var = sys.argv[1]
    
    os.system('steghide extract -sf file1.jpg -p %s' %var)
    os.system('steghide extract -sf file2.jpg -p %s' %var)
    os.system('steghide extract -sf file3.jpg -p %s' %var)
    os.system('steghide extract -sf file4.jpg -p %s' %var)
    os.system('steghide extract -sf file5.jpg -p %s' %var)
    os.system('steghide extract -sf file6.jpg -p %s' %var)
    os.system('steghide extract -sf file7.jpg -p %s' %var)
    os.system('steghide extract -sf file8.jpg -p %s' %var)
    os.system('steghide extract -sf file9.jpg -p %s' %var)
    
    在命令中运行此命令:

    python sample.py "your passphrase here"
    

    谢谢,但我实际上没有访问第一个程序的权限。我把文件给它,然后它把它收进来,问我一个密码。老实说,我甚至不确定这个程序是否是用python编写的。@Ironstone你如何运行这个程序?很抱歉,我对Linux没有经验(使用VM进行竞争)。目前,我在终端中运行一个关键字,后跟参数。老实说,我甚至不确定它是用python编写的,但它请求input()的方式让我有这种感觉,因为在有人输入某个内容之前,它不会打印任何内容。@Ironstone您使用terminal运行应用程序吗?您插入并输出的命令的任何示例?它是steghide,所以我运行'steghide extract-sf file.jpg',然后我会收到“输入密码短语:”的提示
    python sample.py "your passphrase here"