I wrote a program to read the command from the yml file, so I will post it. yml file
cmd1:
command: ls -l
type: ls
cmd2:
command: ls -a
type: ls
python code
import subprocess
import yaml
with open('sample.yml') as file:
obj = yaml.safe_load(file)
cmd1 = obj['cmd1']['command']
types = obj['cmd1']['type']
print('The execution mode is', types,'is.')
print(cmd1)
subprocess.run(cmd1, shell=True)
print('\n')
cmd2 = obj['cmd2']['command']
types = obj['cmd2']['type']
print('The execution mode is', types,'is.')
print(cmd2)
subprocess.run(cmd2, shell=True)
The run mode is ls.
ls -l
total 12
-rwxrwxrwx 1 guest guest 411 Nov 2 09:40 command.py
-rwxrwxrwx 1 guest guest 380 Nov 2 09:06 memo.md
-rwxrwxrwx 1 guest guest 92 Nov 2 09:27 sample.yml
The run mode is ls.
ls -a
. .. command.py memo.md sample.yml
Recommended Posts