0

Hi I want create a python script that executes a command line cmd.exe with echo off and with this comand below

unrar.exe -e -w -b compression.rar c:/tmp

notepad.exe readdocument.txt

and then after this command line must close the command line , and must execute a normal python script , which is this one below

os.rename('readdocument.txt','readdocument-done.txt') import urllib testfile = urllib.URLopener() testfile.retrieve("http://randomsite.com/file.gz", "file.gz") 

how can I create this script correctly?

2
  • 2
    Possible duplicate of Calling an external command in Python Commented Nov 28, 2016 at 7:24
  • If you have echo off, why run cmd.exe? What's wrong with just running the programs one after the other from Python? Commented Nov 28, 2016 at 8:10

2 Answers 2

0

I think you have a windows execution environment and what you are possibly looking for is:

  1. A batch script:

    Quick intro: https://www.tutorialspoint.com/batch_script/index.htm

  2. Or Powershell script:

    https://blog.udemy.com/powershell-tutorial/

  3. Alternatively, you may use Python's subprocess module to execute native commands:

    Using subprocess to run Python script on Windows

Sign up to request clarification or add additional context in comments.

1 Comment

I want to use only python
0

Do you want to redirect the output to stdout? if so, you can do this by using:

subprocess.call(['commands','here']) import subprocess subprocess.call(['unrar', 'e', 'w', 'b', 'compression.rar', 'c:/tmp'], stdout=subprocess.PIPE) 

It will return 0 if successful else 1.

Comments