Running programs from a Python script


 
Thread Tools Search this Thread
Top Forums Programming Running programs from a Python script
# 1  
Old 01-18-2011
Running programs from a Python script

Any idea how I can run a program from a phyton script?

For example, in csh I will do

Code:
      $tpath/tsimplex base=$fbase data=$fdata restore=$frestore  \
          nxp=$nx nzp=$nz param=$param intp=$intp nlay=$nlay     \
          varp=$varp sigma0=$sigma maxiter=$maxiter tol=$tol     \
          dtau=$dtau mdacc=$mdacc mindist=$mindist maxitertp=$maxitertp  \
          outmod=$foutmod expl=$fexpl backup=$fbackup            \
          vrb=$vrb >& $fsmplog

How can I do the same thing in phyton???
# 2  
Old 01-18-2011
I'm guessing you mean Python. I think Python has a C-like system("command"); call. You'll have to build a string, then feed it into it.
# 3  
Old 01-18-2011
Yep Python

---------- Post updated at 01:31 PM ---------- Previous update was at 01:30 PM ----------

Would something like this work???

Code:
        "%s/tsimplex base=%s data=%s inmod=%s nxp=%s nzp=%s param=%s  \
        intp=%s nlay=%s varp=%s sigma0=%s maxiter=%s tol=%s dtau%s mdacc=%s 
        mindist=%s maxitertp=%s outmod=%s expl=%s backup=%s vrb=%s >& %s \
        "%(tpath,fbase,fdata,fstmod,nxp,nzp,param,intp,nlay,varp,sigma,maxiter,
           tol,dtau,mdacc,mindist,maxitertp,foutmod,fexpl,fbackup,vrb,fsmplog)

---------- Post updated at 01:55 PM ---------- Previous update was at 01:31 PM ----------

I also have the following code that complains when encounters &&

Code:
    if (not isinstance(stmod,types.NoneType)) &&  (isinstance(restore,types.NoneType)):
        print ""
        print "ERROR: Can't use both -fstmod and -frestore options"
        print "       Set either -fstmod or -frestore options"
        print ""
        sys.exit(-1)

---------- Post updated at 02:24 PM ---------- Previous update was at 01:55 PM ----------

Seems I need to use 'and' instead of '&&'
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

CRONTAB - one python script is not running

Hi! I'm using a RaspberryPi with standard Raspbian. Currently I'm working on some sort of weather station. For now I have three python scripts - one which is updating txt files for website - update1m.py ( it will not be necessary in few next days so I'll delete it) , second one for updating... (4 Replies)
Discussion started by: bartocham
4 Replies

2. Programming

Running python script in cygwin

I have python installed here on windows: C:\Python27 and can run a script from the command line but would rather use cygwin. $ cd "C:\Users\cmccabe\Desktop\annovar" cmccabe@DTV-L2231M5J /cygdrive/c/Users/cmccabe/Desktop/annovar $ python run_batch_job.py Traceback (most recent call last):... (3 Replies)
Discussion started by: cmccabe
3 Replies

3. Shell Programming and Scripting

Running external programs inside an if then else

Good morning, First time poster. be gentle! :) I do not know coding all that well but I can hack the hell out of example scripts! I just cant wrap my brain around this one. Im trying to run two grep statements in the first IF statement and doing an AND between them. Something is going... (6 Replies)
Discussion started by: mrplow2k69
6 Replies

4. Shell Programming and Scripting

Run multiple python programs sequentially.

I HAVE WRITTEN NINE PYTHON CODES TO PERFORM A TASK ........ I WISH TO RUN THEM SEQUENTIALLY. eg. code1__code2 >>>>>>>>code9.py TO GET DESIRED OUTPUT. PLS HELP ME WRITTING SHELL SCRIPT .. I HAVE TO DISTRIBUTE THESE CODE FOR BEING USED BY OTHERS. (2 Replies)
Discussion started by: upvan111
2 Replies

5. Shell Programming and Scripting

Running programs

I have installed a software called GMT, then writing a script that call the new programs ./example02.sh but I am getting ./example02.sh: line 20: gmtset: command not found I have done ./configure make make install (0 Replies)
Discussion started by: kristinu
0 Replies

6. Shell Programming and Scripting

Running programs in perl

I am trying to run a program called GMT using perl. Cannot make to run. I have tried using exec("date"); as a test but when I use exec($try); nothing happens. #!/usr/bin/perl print "$#ARGV\n"; if ($#ARGV != 3) { print "usage: jcdplot.perl\n"; exit; } $h = $ARGV;... (1 Reply)
Discussion started by: kristinu
1 Replies

7. UNIX for Advanced & Expert Users

running X-11 programs as root

Hello, I would like to run gedit as root while logged into my regular user account. When I try to launch gedit from the command line as super user, I get this message: Gtk-WARNING **: cannot open display: Any suggestions or word arounds? It would make my life a lot simpler to edit files... (8 Replies)
Discussion started by: Allasso
8 Replies

8. Shell Programming and Scripting

Finding The Number Of Programs That A Given User Running On A TERMINAL

How To Find The Number Of Programs That A User Running ON A GIVEN TERMINAL (4 Replies)
Discussion started by: venkata.ganesh
4 Replies

9. UNIX for Dummies Questions & Answers

installing/running programs.

Hey folks, i'm a total newbie at linux (only installed it yesterday) so don't be mad at me for querying this. I downloaded firefox, and unpacked the library files and binaries into /usr/lib/firefox. Now, am I correct in thinking that to run it, I need to enter the 'sh /usr/lib/firefox' command into... (4 Replies)
Discussion started by: shep
4 Replies

10. UNIX for Dummies Questions & Answers

running preinstalled programs

Im using the knoppix version of linux, which is booting straight off the cd, and it shows my c drive (partiton) that has all my programs i have installed in my xp operating system. Im wondering if theres a way i can play my games like lotr return of the king, or jedi academy, in knoppox. it shows... (2 Replies)
Discussion started by: jestra
2 Replies
Login or Register to Ask a Question