Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl Command from Perl Script

Status
Not open for further replies.

SandyY

MIS
Sep 7, 2010
1
US
Hi,

I am having one question. I hope it's easy for those who had been doing Perl for long.

Question - I have a perl command line utility for removing ctrl M character from my Sybase BCP file and i want to run this from perl script. I can pass the file name as argument but i do not knwo how to execute the command line interpreter from this perl program


Thanks
 
Less description could not have been more possible.

Using the system function will let you run a command as if you were at the command line.

my $args = 'file_with_damn_carat_m.txt';
system("perl script_name.pl $args");

$args would be a variable (in your case, the file to be manipulated).

Hope this helps!

--Jim



 
Yes, if you are calling a perl script from a perl script, u could use the system call, as you could use the system call if you want to execute a sed ar awk command, if you just want to invove the command line intrepreter as you stated, try and use "perl -e expression" (minus the quotes)should allow you to do what you want, this is the same in sed, sed -e will allow the intrepretation and execution of sed commands.
 
I find that a short, accurate, answer is often the best route, I think you may have mis understood the question,

Q:how to execute the command line interpreter from this perl program

A:perl -e


just because your suggestion of using system made no sense don't get mad, lets all just get along

now bow down to the whizard...jk lol
 
Ohhhhhh now I see, in order to execute a command line interpreter FROM a perl program, all you have to do is type:

perl -e name_of_script

Oh, what's this? I must have a bad version of Perl on my computer because it doesn't seem to work for me... no wait, it's merely becuase you're incorrect.

Accuracy and brevity: the key to communication. Unfortunately you seem to have settled for 1 out of 2.

If sandyy has developed a command line utility, she probably know's how to use it. I think she wants to know how to execute it from her script, and your one liner aint it.

Sorry if this also makes no sense to you.

--Jim
 
i guess you could have sold me on :
system("perl -e command");

nice work chiefy
 
sorry man, i'm a little too used to ksh so I'll go back to the unix forum now, cause there ya need the famous '-e' ..but don't you need it if it isn't in a script, and it's just a command you exutute from the command line?..i guess I may have been confused?...give me something:)

 
I have a similar problem. I have a one line perl command that works perfect from the command line (linux), but when trying to use it in another script with the system command, I get:
sh: syntax error near unexpected token `f)'
sh: -c: line 1: `perl -p -i -e 's/template.com/test.com/g;' 0 10 6 4 3 2 1 0find /home/test/* -type f)'

The command:
perl -p -i -e "s/template.com/test.com/g;" $(find /home/test/* -type f)

I tried the following inside my script:
system ("perl -p -i -e 's/template\.com/test\.com/g;' $(find /home/test/* -type f)");

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top