Please have a look over here :)

http://stackoverflow.com/questions/4256107/running-bash-commands-in-python

Mainly

vim /tmp/call.py

 

Don't use os.system. Use subprocess.

Like in your case:

#bashCommand ="cwm --rdf test.rdf --ntriples > test.nt"
bashCommand ="ls"
import subprocess
#process
= subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE) # we need to split() the command if there are many flags
output
= process.communicate()[0]
process = subprocess.Popen(bashCommand, stdout = subprocess.PIPE)
print output # for python2
#print(output) # for python3+
python /tmp/call.py

 

You will get:

alex@universe /tmp $ python call.py 
call.py
CRX_75DAF8CB7768
fcitx-socket-:0
hsperfdata_alex
keyring-StERCr
mintUpdate
orbit-alex
pulse-2L9K88eMlGn7
pulse-PKdhtXMmr18n
untitled4897414270208832777.tmp

 

The output result is the same as the result gotten from BASH

 

相关文章:

  • 2022-12-23
  • 2021-09-21
  • 2021-12-24
  • 2022-12-23
  • 2021-05-29
  • 2022-02-28
  • 2022-02-13
  • 2022-01-09
猜你喜欢
  • 2021-06-20
  • 2021-05-17
  • 2022-12-23
  • 2022-12-23
  • 2021-12-14
  • 2021-12-27
  • 2022-02-05
相关资源
相似解决方案