Skip to content Skip to sidebar Skip to footer

How To Call A Cmd File Within Python Script

This is the python script will do. The question is how to call the external cmd file within the function? Read a CSV file in the directory. If the content in 6th column is equa

Solution 1:

Take a look at the subprocess module.

importsubprocessp= subprocess.Popen(['TransferProd.cmd'])

You can specify where you want output/errors to go (directly to a file or to a file-like object), pipe in input, etc.

Solution 2:

import osos.system('TransferProd.cmd')

This works in both unix/windows flavors as it send the commands to the shell. There are some variations in returned values though! Check here.

Solution 3:

  1. If you don't need output of the command you could use: os.system(cmd)
  2. The better solution is to use:

    from subprocess import Popen, PIPE
    proc = Popen(cmd, shell = True, close_fds = True)
    stdout, stderr = proc.communicate()
    

Post a Comment for "How To Call A Cmd File Within Python Script"