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')
icode
  • 47
  • 10

1 Answers1

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")
temp123
  • 362
  • 1
  • 4
  • 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. – icode Aug 21 '19 at 13:25
  • 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. – temp123 Aug 21 '19 at 13:34
  • I want to add syntax in my native shell-environment – icode Aug 21 '19 at 13:35
  • I see, in that case I think what you need is to add an alias. I suggest you take a look here for Windows: https://superuser.com/questions/1134368/create-permanent-doskey-in-windows-cmd Linux: https://stackoverflow.com/questions/30585918/creating-an-alias Mac: https://stackoverflow.com/questions/8967843/how-do-i-create-a-bash-alias – temp123 Aug 21 '19 at 13:42
  • I mean inside my python interactive shell not my terminal – icode Aug 21 '19 at 13:44
  • example: a = input();!cls!;print(a) – icode Aug 21 '19 at 13:56
  • Do you mean to make a custom statement in Python? In that case, see this link: https://stackoverflow.com/questions/214881/can-you-add-new-statements-to-pythons-syntax – temp123 Aug 21 '19 at 14:01
  • Thank you for your answer. Would you please give me a good score for my question? – icode Aug 21 '19 at 18:55