Here is the code:

# -*- coding: utf-8 -*- import subprocess import argparse parser = argparse.ArgumentParser(description='Shell execute') parser.add_argument('-c', help = 'command') parser.add_argument('-a', help = 'args') args = parser.parse_args() command = args.c args = args.a def launchWithoutConsole(command, args): startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW return subprocess.Popen([command] + args, startupinfo=startupinfo).wait() try: launchWithoutConsole(command, args) except TypeError: exit() 

Then I’ll address it like this: python shellexlex.py -c help -a <here are the arguments>
I can't figure out how to pass in -a 2 or more arguments.

PS Here's how to call it turned out in code, but I need python shellex execution.py -c help -a <here arguments>

 launchWithoutConsole("help", [">","filename.txt"]) 
  • through space for example - Grundy
  • If after a space then error: argument -a: expected one argument - Alex Firsov

1 answer 1

I was wrong launchWithoutConsole("help", [">","filename.txt"]) it did not work, but if you stuff a command into a .bat file and launchWithoutConsole("h.bat", [">","filename.txt"]) everything will work.