Running programs in perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running programs in perl
# 1  
Old 12-26-2009
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.

Code:
#!/usr/bin/perl

  print "$#ARGV\n";

  if ($#ARGV != 3) {
      print "usage: jcdplot.perl\n";
      exit;
  }

  $h = $ARGV[0];

# Get arguments when user includes them
# Change annotation if depth variation in plot gets too large
  $dz = 25.0;
  $zdif = 50.0;
  if ( $#ARGV == 3 ) {
      $zmin = $ARGV[0];
      $zmax = $ARGV[1];
      $vmin = $ARGV[2];
      $vmax = $ARGV[3];
      $dz = $zmax - $zmin;
      print "dz $dz $zdif";
      if ( $dz > $zdif ) {
          $annot = "a10.0f1.0";
          print " a10.0f1.0\n";
      }
      else {
          $annot = "a1.0f0.5";
          print " a1.0f0.5\n";
      }
  }

# Title and description of travel time plotting axes
  $TITLE = "JCD Model S sound speed (red) and interpolated (black)";
  $ZDESC = "Depth, z, Mm";
  $VDESC = "Sound speed, v, Mm/min";

  $try = "psxy jcd.vtab -JX10i/5.5i -R-0.5/25/-0.5/5 -Wred -Ba1.0f0.5:$ZDESC:/a1.0f0.5:$VDESC::.$TITLE:WSne -m -K > jcdint.ps";
  print "TRY: $try\n";

# No arguments to script
  if ( $#ARGV == 3 ) {
    exec("date");
  }
  exec($try);

# 2  
Old 12-26-2009
Quote:
Originally Posted by kristinu
... but when I use exec($try); nothing happens.
...
How do you figure out nothing happens ?

Seems like your command redirects the output to "jcdint.ps". Do you see it created after execution of the Perl program ?

Run the following on the shell prompt and see if "jcdint.ps" was created/written into. I'd assume this is what your Perl program is trying to execute.

Code:
psxy jcd.vtab -JX10i/5.5i -R-0.5/25/-0.5/5 -Wred -Ba1.0f0.5:Depth, z, Mm:/a1.0f0.5:Sound speed, v, Mm/min::.JCD Model S sound speed (red) and interpolated (black):WSne -m -K > jcdint.ps

Also, remove the redirection part "> jcdint.ps" and see if it executes without error on the shell prompt first.

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Programming

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 $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 \ ... (2 Replies)
Discussion started by: kristinu
2 Replies

3. 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

4. UNIX for Dummies Questions & Answers

Are programs like sys_open( ) ,sys_read( ) et al examples of system level programs ?

Are the programs written on schedulers ,thread library , process management, memory management, et al called systems programs ? How are they different from the programs that implement functions like open() , printf() , scanf() , read() .. they have a prefix sys_open, sys_close, sys_read etc , right... (1 Reply)
Discussion started by: vishwamitra
1 Replies

5. Shell Programming and Scripting

working with other programs in perl

Hi, I'm still new to perl, and I'm trying to figure out how to work with data output from another program. For example, from a command line I can run "foo -xyz" and it will produce the output I am looking for, which is several lines of text that I will then parse and manipulate within the perl... (6 Replies)
Discussion started by: Decoy
6 Replies

6. Shell Programming and Scripting

Perl call C programs

Hi, I am a beginner in Perl programming. Now i need to call a C program from a perl program ...Can any one please help me and give any details how i can do this. Thanks and Regards (3 Replies)
Discussion started by: gjithin
3 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