0

I have more than one command that has to be executed on the shell and I want to the run all the commands on the same shell . I have the commands stored in a file(command.txt) and I want all of them to be executed in a single go using the subprocess.run() function in python

I tried something like this but this doesn't work.

subprocess.run(str(open("command.txt")),shell = True) 
1
  • Do you know how to read a file you opened? How to extract its content?
    – ForceBru
    CommentedApr 13, 2020 at 12:46

1 Answer 1

1
subprocess.run(['sh', 'command.txt']) 

Note that we are not using shell=True here, as we already start sh ourselves.

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.