0

So essentially what I am trying to do is write a python script that will execute a series of commands within an application's own command line. I am aware of the subprocess module and how I can use it to execute commands in shell, one after the other, but I cannot seem to figure out how to navigate within an application's shell once I have successfully executed it using my script. For example, say I am using the application 'app'. I execute app using the command 'runmod app' from shell successfully, and then this launches the application in shell with the application's internal command line leading with 'app>'. How can I execute commands from this internal app command line using my script?

Farhana
  • 11
  • 2
  • Are you looking for something like `os.system('my command line argument')`? – Reedinationer Mar 18 '19 at 22:04
  • Seems like you could use a pipe to send commands to it to be executed (`subprocess` supports them). – martineau Mar 18 '19 at 22:08
  • 1
    Many applications have an interactive command line, such as `sh` and `python`. They usually also have an option to evaluate commands non-interactively, e.g. `sh -c 'my command'` or `python -c 'my command'`. You should check your application can do the same. If it can't, you can run the application's interactive command line and [write the commands to the process's stdin](https://stackoverflow.com/questions/8475290/how-do-i-write-to-a-python-subprocess-stdin) – that other guy Mar 18 '19 at 22:09
  • Please show the relevant code. Please state where the error is encountered. Also see [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – jww Mar 18 '19 at 23:06

1 Answers1

0

You can use this packages, this is a little example for a tiny college project.

#proyecto.py
import os, sys
import argparse

parser = argparse.ArgumentParser()
# Define flags
parser.add_argument('-f', '--front', dest='front', help='Path to front view video in mp4, avi or wmv format')
parser.add_argument('-b', '--back', dest='back', help='Path to back view video in mp4, avi or wmv format')
parser.add_argument('-r', '--right', dest='right', help='Path to right view video in mp4, avi or wmv format')
parser.add_argument('-l', '--left', dest='left', help='Path to left view video in mp4, avi or wmv format')
....
....
....


args = parser.parse_args()
if validate_flags(args.front, args.back, args.left, args.right, args.video_output):
    front = args.front
    back = args.back
    left = args.left
    right = args.right
    video_out = args.video_output

It should be executed with

python proyecto.py -i video_ex.mp4 -o out.avi -s 480 --scale 0.5

Geancarlo Murillo
  • 509
  • 1
  • 5
  • 14