You have:
- A program (python script)
- N (9) files to process with the program
- 1 argument (input) for the program
Now, you want to run the script from command line for N (9) files with the same argument, right?
My suggestion will be writing another script to run the script for that N files with same input argument.
A basic introduction for system command line argument:
# Module sys has to be imported:
import sys
# Iteration over all arguments:
for eachArg in sys.argv:
print(eachArg)
Example call to this script :
python argumente.py python course for beginners
The output:
argumente.py
python
course
for
beginners
Now we can modify this simple example to your case. First, create a new python program and import your python script, let’s say your python program name is 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)
where your call to this script is (let’s name this script as sample.py):
python sample.py "your input here"
Now it will get the same input and run for N files.
[Updated Answer after Discussion]
Since the questioner is using steghide with command and he is required to enter the passphrase every time. From the steghide doc, you can add a passphrase argument to the command.
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)
Run this in command:
python sample.py "your passphrase here"
6
solved Python script for executing repetitive script input