[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

shell script with arguments within perl script

jay

5/2/2007 8:23:00 PM

Hi! I wanted to run the system command with in Perl script to execute
shell script with argument. I need to know the correct syntax for the
arguments.

Ex.)
#/opt/bin/perl

system("shellscript.sh" <arg1>, <arg2> <arg3>);

I am getting syntax error. If i get rid of the arg1-3 then the shell
script runs just fine.

thanks.

--
Posted via http://www.ruby-....

7 Answers

John Joyce

5/2/2007 8:52:00 PM

0


On May 3, 2007, at 5:22 AM, jay wrote:

> Hi! I wanted to run the system command with in Perl script to execute
> shell script with argument. I need to know the correct syntax for the
> arguments.
>
> Ex.)
> #/opt/bin/perl
>
> system("shellscript.sh" <arg1>, <arg2> <arg3>);
>
> I am getting syntax error. If i get rid of the arg1-3 then the shell
> script runs just fine.
>
> thanks.
>
> --
> Posted via http://www.ruby-....
>
in Ruby:

system( command, arg, arg, arg)

Returns true if command runs successfully, false otherwise.

There is also:

exec( command, arg, arg, arg)

Exact behavior is platform dependent. One might presume that since
Ruby borrows a fair amount from Perl, that there may be something
similar going on.

Chad Perrin

5/2/2007 9:30:00 PM

0

On Thu, May 03, 2007 at 05:22:54AM +0900, jay wrote:
> Hi! I wanted to run the system command with in Perl script to execute
> shell script with argument. I need to know the correct syntax for the
> arguments.
>
> Ex.)
> #/opt/bin/perl
>
> system("shellscript.sh" <arg1>, <arg2> <arg3>);
>
> I am getting syntax error. If i get rid of the arg1-3 then the shell
> script runs just fine.

Are you using commas exactly as shown? If so, that's probably the
problem. Try this instead:

system("foo.sh", "bar", "baz", "qux");

. . where bar, baz, and qux are your arguments. You could also simply
do something like one of the following:

system("foo.sh bar baz qux");

my $foo = "foo.sh";
my @args = qw(bar baz qux");
system("$foo @args");

my @command_and_args = qw(foo.sh bar baz qux);
system("@command_and_args");

In each case, assuming the use of system() is the only thing on that
line of the program, the parentheses are optional.

You *are* using the strict and warnings pragmas -- right? You should
always include the following two lines at the beginning of any Perl
script while working on it to help with debugging and good programming
practice:

use strict;
use warnings;

You should also make use of perldoc, which should be installed on your
system. With the -f option, the perldoc command can be used to look up
information about a specific function. In this case, you can learn more
about how system() works with the following commmand, for instance:

perldoc -f system

I hope that helps.

--
CCD CopyWrite Chad Perrin [ http://ccd.ap... ]
Leon Festinger: "A man with a conviction is a hard man to change. Tell him
you disagree and he turns away. Show him facts and figures and he questions
your sources. Appeal to logic and he fails to see your point."

Chad Perrin

5/2/2007 9:31:00 PM

0

On Thu, May 03, 2007 at 05:22:54AM +0900, jay wrote:
> Hi! I wanted to run the system command with in Perl script to execute
> shell script with argument. I need to know the correct syntax for the
> arguments.

Oh, one other thing -- you're asking this of a Ruby community, not a
Perl community. Since this was apparently posted via the forum, rather
than the mailing list or newsgroup, I suspect what you actually want
is the PerlMonks website:

http://www.per...

--
CCD CopyWrite Chad Perrin [ http://ccd.ap... ]
Brian K. Reid: "In computer science, we stand on each other's feet."

Robert Dober

5/3/2007 4:49:00 AM

0

On 5/2/07, Chad Perrin <perrin@apotheon.com> wrote:
When there are people behaving strangly in nice restaurants one can
suspect that they are Critics (sp?) from Michelin or whatever
Guide(1).
Chad I guess you just got us our first "Toque" ;)

Cheers
Robert

(1) Although that is probably never the case.

--
You see things; and you say Why?
But I dream things that never were; and I say Why not?
-- George Bernard Shaw

John Joyce

5/3/2007 4:59:00 AM

0


On May 3, 2007, at 6:31 AM, Chad Perrin wrote:

> On Thu, May 03, 2007 at 05:22:54AM +0900, jay wrote:
>> Hi! I wanted to run the system command with in Perl script to execute
>> shell script with argument. I need to know the correct syntax for the
>> arguments.
>
> Oh, one other thing -- you're asking this of a Ruby community, not a
> Perl community. Since this was apparently posted via the forum,
> rather
> than the mailing list or newsgroup, I suspect what you actually want
> is the PerlMonks website:
>
> http://www.per...
>
> --
> CCD CopyWrite Chad Perrin [ http://ccd.ap... ]
> Brian K. Reid: "In computer science, we stand on each other's feet."
>
www.perlmonks.org indeed!
Good place for good Perl.

Chad Perrin

5/3/2007 8:48:00 AM

0

On Thu, May 03, 2007 at 01:49:16PM +0900, Robert Dober wrote:
> On 5/2/07, Chad Perrin <perrin@apotheon.com> wrote:
> When there are people behaving strangly in nice restaurants one can
> suspect that they are Critics (sp?) from Michelin or whatever
> Guide(1).
> Chad I guess you just got us our first "Toque" ;)
>
> Cheers
> Robert
>
> (1) Although that is probably never the case.

Uh, what? What does a hat have to do with this?

I think you lost me.

--
CCD CopyWrite Chad Perrin [ http://ccd.ap... ]
Paul Graham: "Real ugliness is not harsh-looking syntax, but having to
build programs out of the wrong concepts."

Chad Perrin

5/3/2007 8:57:00 AM

0

On Thu, May 03, 2007 at 05:47:56PM +0900, Chad Perrin wrote:
> On Thu, May 03, 2007 at 01:49:16PM +0900, Robert Dober wrote:
> > On 5/2/07, Chad Perrin <perrin@apotheon.com> wrote:
> > When there are people behaving strangly in nice restaurants one can
> > suspect that they are Critics (sp?) from Michelin or whatever
> > Guide(1).
> > Chad I guess you just got us our first "Toque" ;)
> >
> > Cheers
> > Robert
> >
> > (1) Although that is probably never the case.
>
> Uh, what? What does a hat have to do with this?
>
> I think you lost me.

Never mind. I get it -- the purpose of the metaphor just slipped by me
for a moment there.

Thanks for the compliment.

--
CCD CopyWrite Chad Perrin [ http://ccd.ap... ]
Amazon.com interview candidate: "When C++ is your hammer, everything starts
to look like your thumb."