1

How to build a new kind of syntax which when has been called run it's value in os.system

while True: a=input('enter your direction: ') if a!='': !dir !+Shell(a) else: print('the dir can not be None') 
6
  • When you say syntax, what do you mean? Is it supposed to be a parseable input to the program that generates an output from os.system? Commented Aug 21, 2019 at 12:19
  • Yes. I mean that Commented Aug 21, 2019 at 12:56
  • Ah I see, please see my answer below. Commented Aug 21, 2019 at 12:59
  • ok, thanks. but I want to use it in my pure python code like: if a==1: !echo !+Shell(a) Commented Aug 21, 2019 at 13:03
  • It's a little hard to understand what you mean, could you provide a code sample? If you would like to change the command based on a variable you simply do: cmd = "new command" Commented Aug 21, 2019 at 13:07

1 Answer 1

1

Based on your clarification, maybe this would work for you:

import subprocess while True: cmd = input("Enter a command: ") if cmd != "": cmd = cmd.split("!")[1] subprocess.call(cmd, shell=True) else: print("Input cannot be None") 
Sign up to request clarification or add additional context in comments.

8 Comments

Well, in your code I should do text parsing. But I want to use it in an eval or exec which I get the input from user.
I'm sorry, not sure I follow. Do you mean to process it as a variable that is not textual input from user or do you mean to change / add syntax in your native shell-environment? Please add some clarification as to what it is you need.
I want to add syntax in my native shell-environment
I see, in that case I think what you need is to add an alias. I suggest you take a look here for Windows: superuser.com/questions/1134368/… Linux: stackoverflow.com/questions/30585918/creating-an-alias Mac: stackoverflow.com/questions/8967843/…
I mean inside my python interactive shell not my terminal
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.