-2

I need help to writing a Python application that needs to run other command line afflictions. For example, when I push "BLABLA" button the Python application call function that run in command line c:\test> BLA.exe blabla, the function return same string so I need to store it in a variable.

So, I don't know how to run command line programs from within Python and get the strings back form that program.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
MAX K
  • 1
  • 1
  • I saw the post and don't understand it ... – MAX K Aug 31 '14 at 12:26
  • Sorry, I didn't read carefully. I removed the duplicate flag. But actually it's answered on [a different stackoverflow question](http://stackoverflow.com/questions/4760215/running-shell-command-from-python-and-capturing-the-output)... – Falko Aug 31 '14 at 12:32

1 Answers1

0

If you need the output of the command, this answer might help:

import subprocess

p = subprocess.Popen(['ls', '-a'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
print out

So in your case the one line might look like this:

p = subprocess.Popen(['BLA.exe', 'blabla'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Community
  • 1
  • 1
Falko
  • 17,076
  • 13
  • 60
  • 105
  • It work only one time , if I run it again with 'blabla2 ' in same program it make some wrong staf ( if i run it directly via command line it work fine :BLA.exe blabla , enter, BLA.exe blabla2 ,enter... ) Any ideas ? – MAX K Aug 31 '14 at 13:52
  • @MAXK: Hm, make sure your program does not change the working directory. But for a more detailed error analysis you might describe the "wrong staff" and post your python code. – Falko Aug 31 '14 at 14:35