1

I need to call a program in command line that will be executed in batch mode. This program receives a file with extension .jlink that contains a series of commands that the program JLink.exe will execute and then close.

I tried to execute in the following way:

os.system('C:/SEGGER/JLink_V490d/JLink.exe -CommanderScript D:\Files\CommandFile.jlink')

But this command executes the program in normal mode, not accepting the arguments.

How can I call as execution of command line and then send that command so the program executes in batch mode with those arguments?

Georgy
  • 6,348
  • 7
  • 46
  • 58
  • https://stackoverflow.com/questions/89228/calling-an-external-command-in-python?rq=1 https://stackoverflow.com/questions/14892355/passing-arguments-into-os-system https://stackoverflow.com/questions/16820420/python-share-the-command-line-argument-to-os-system-call – 0xAli Sep 24 '14 at 12:14

1 Answers1

1

Use subprocess:

subprocess.call(["C:\SEGGER\JLink_V490d\JLink.exe", 
                 "-CommanderScript", "D:\Files\CommandFile.jlink"])

You can also use shell=True to just execute a command directly in a shell (what you were trying to do with os.system), but this is not recommended because it's a security hazard.

More info here: https://docs.python.org/2/library/subprocess.html

letitbee
  • 3,576
  • 19
  • 29