Thread: Howto: Run bash shell commands from within Python
the subprocess module can used call command-line programs within python. however, syntax long-winded , hard remember. convenient simple python script can save time is:
example uses are:code:def bash(cmd,cwd=none): '''runs command in bash shell''' print(cmd) retval = subprocess.popen(cmd, shell=true, \ stdout=subprocess.pipe, cwd=cwd).stdout.read().strip('\n').split('\n') if retval==['']: return(0) else: return(retval)
andcode:bash('convert myfile.png myfile.jpg')
code:myfilelist = bash('ls *.jpg',cwd='mydirectory')
Forum The Ubuntu Forum Community Other Discussion and Support Tutorials Outdated Tutorials & Tips Howto: Run bash shell commands from within Python
Ubuntu
Comments
Post a Comment