Can you run a unix script from a perl program

Hi all
i have a unix script reformatter.sh
i have a process whereby this script reformats a file before a perl program is used to update it
i am having a little problem automating the entire process . is there a way whereby i can call the unix script from the perl program ?

Yes, you can use backticks (accent-graves) to run a Unix script/command etc. just like you do in the Bash shell. Or you can use the system command.

Check:

perldoc -f system

tyler_durden

Just curious.

Are users dwightja and dwightja24 the same person?

got confused with login names

yes i am

this is what i tried

the script takes two variables 1 input 2 output name

!/usr/bin/env perl

system("reformatnwc.sh CustomerData.txt tt.txt");

didnt work

If you ask me, this is the vaguest answer you could give - "didn't work". It's like saying "I tried to reach office on time today. Didn't work."

Well ?

  • Did you not get up on time ?
  • Did you miss your bus ?
  • Did your car not start ?
  • Did you get stuck in traffic ?
  • Did you get a flat tire ?
  • Did you meet with an accident ?
  • Did your tie get stuck in the sliding office door ?
    As you can see, with a vague statement like that, the possibilities are endless.

And pertaining to your script:

  • Do you know how to run a perl program ?
  • Do you know what that first line means ?
  • Do you know what should be put in that first line ?
  • Did you invoke the program correctly ?
  • Did your program fail miserably ?
  • Did you get an error message ?
  • Were you able to run the program successfully, but did not get the results you expected ?
  • Does that script work properly when invoked on the terminal prompt ?
  • Did you capture and examine the exit status in the perl program ?
  • Did you read the documentation of the system function in perldoc (the command that was posted earlier) ?

Again, the possibilities are endless.
And without a crystal ball with us to gaze at, we are at loss to figure out what happened in your computer.

tyler_durden

ksh: syntax error: `(' unexpected

all i had in the script is

!/usr/bin/env perl
#
system("reformatnwc.sh CustomerData.txt tt.txt");

tried running it from the propmt using . ./<program_name>

Try replacing the first line with #!/usr/bin/perl

tried running it straigth from the prompt without the fullstop
awk: syntax error near line 5
awk: illegal statement near line 5
with the fullstop
ksh: syntax error: `(' unexpected

what's the 'fullstop'?
Without seeing the ksh script you're executing, it's impossible to help you further.
Post the script you're executing using code tags.

see scripts attached
i was just trying to test fadditional lines in the perl script
reformat .sh reformats the file customerdata.txt
all files are in the same folder and have executable permissions
after i get the test.pl to work
i am going to try and integrate it into the bpformatter.txt
above the open( my $in, $self->{FILENAME} ) or $halt = 1;

really and truly what has occured is that i wanted to do the changes in NWCformatter
in that each record now actullay contains two records
this is why i initially created the reformatnwc.sh
as i did not know how to accomplish this in the nwcformatter perl script
as it seems that script can only return 1 record

if you're under Sun/Solaris, try using '/usr/bin/nawk' or '/usr/xpg4/bin/awk' instead of plain/old/buggy 'awk' (in your reformatnwc.sh).

ill try that but just to note the reformatnwc.sh is working
when i execute it by itself
its when i try and run it from the perl command that it fails

turns out perl environment had changed so was referring to a library location that didnt exist