Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > perl program with "&"

Reply
Thread Tools

perl program with "&"

 
 
yezi
Guest
Posts: n/a
 
      08-03-2005
Dear ALl:

The program now is following:
#!/usr/bin/perl
use warnings;
use strict;

my $filename;
my $cmdline;

$filename="/home/binye/test_perl/testdownload.txt";
open( FILE, "< $filename" ) or die "Can't open $filename : $!";

while( <FILE> ) {

print "Processing wget.";
my $cmdline="wget -w 50 -q http://$_ & tcpdump -c 20 -i eth0 src host
$_ -w $_.dmp ";
system($cmdline);
print "done ...w $_..";

}

close FILE;

I try to run it, by using the & the waring message is :

syntax error near unexpected token `&'
sh: -c: line 2: ` & tcpdump -c 20 -i eth0 src host www.cron.com'

Then I exchange the & to \$, still same problem.

So I donot know how to make the program works now. Thanks for any
comments

 
Reply With Quote
 
 
 
 
Ian Wilson
Guest
Posts: n/a
 
      08-04-2005
yezi wrote:
> Dear ALl:
>
> The program now is following:


Is this a followup to an earlier posting? Please read the posting
guidelines at
http://mail.augustmail.com/~tadmc/cl...uidelines.html

> #!/usr/bin/perl
> use warnings;
> use strict;
>
> my $filename;
> my $cmdline;
>
> $filename="/home/binye/test_perl/testdownload.txt";
> open( FILE, "< $filename" ) or die "Can't open $filename : $!";
>
> while( <FILE> ) {
>
> print "Processing wget.";
> my $cmdline="wget -w 50 -q http://$_ & tcpdump -c 20 -i eth0 src host
> $_ -w $_.dmp ";


You may want to check that $cmdline actually contains what you think it
does.

> system($cmdline);
> print "done ...w $_..";
>
> }
>
> close FILE;
>
> I try to run it, by using the & the waring message is :
>
> syntax error near unexpected token `&'
> sh: -c: line 2: ` & tcpdump -c 20 -i eth0 src host www.cron.com'


The "sh" at the beginning means that this is not a perl error message,
it is a shell error message. your system call passes your command to the
shell. This means that this isn't really a perl question.


>
> Then I exchange the & to \$, still same problem.


You need to understand shell programming. I suspect that randomly
changing symbols rarely achieves anything useful.

>
> So I donot know how to make the program works now. Thanks for any
> comments
>


I'd try typing your command into a shell command line before embedding
it in a perl script.

I suspect you need to start tcpdump before running wget (assuming you
want to capture some HTTP traffic). If that is the case then I think
'tcpdump <options> ; wget <options>' would be more appropriate.

I don't know why you'd want to do this since wget has some handy options
for capturing the HTML and host responses etc.

In fact I don't know why you are using system('wget') instead of a perl
HTTP module - wouldn't that make it a lot easier?
 
Reply With Quote
 
 
 
 
chris-usenet@roaima.co.uk
Guest
Posts: n/a
 
      08-04-2005
yezi <> wrote:
Y> while( <FILE> ) {
Y> my $cmdline="wget -w 50 -q http://$_ & tcpdump -c 20 -i eth0
src host $_ -w $_.dmp ";
Y> system($cmdline);


Ian Wilson <> suggested:
IW> You may want to check that $cmdline actually contains what you
IW> think it does.

This is an excellent suggestion.


Y> I try to run it, by using the & the waring message is :
Y> syntax error near unexpected token `&'
Y> sh: -c: line 2: ` & tcpdump -c 20 -i eth0 src host www.cron.com'

IW> The "sh" at the beginning means that this is not a perl error message,
IW> it is a shell error message. your system call passes your command
IW> to the shell. This means that this isn't really a perl question.

Actually, in this case it is a perl related problem. The hint is that
sh is complaining about line 2. I'll wager that the OP didn't expect
there to be more than one line in their system() shell call.


IW> I'd try typing your command into a shell command line before embedding
IW> it in a perl script.

The command will work, because it won't be exactly the same as what's
passed via system(). It's Yezi's misunderstanding of what it returned
from <FILE> that's at fault here.

Yezi, I suggest you go and read "perldoc -f chomp" and see if that helps
resolve the problem you're seeing.

Chris
 
Reply With Quote
 
????? ????? (Shantanoo Mahajan)
Guest
Posts: n/a
 
      08-11-2005
yezi wrote:

> Dear ALl:
>
> The program now is following:
> #!/usr/bin/perl
> use warnings;
> use strict;
>
> my $filename;
> my $cmdline;
>
> $filename="/home/binye/test_perl/testdownload.txt";
> open( FILE, "< $filename" ) or die "Can't open $filename : $!";
>
> while( <FILE> ) {
>
> print "Processing wget.";
> my $cmdline="wget -w 50 -q http://$_ & tcpdump -c 20 -i eth0 src host
> $_ -w $_.dmp ";
> system($cmdline);
> print "done ...w $_..";
>
> }
>
> close FILE;
>


Are you trying to run wget in background? If yes, have a look at '-b' or
'--background' option of wget.

Regards,
Shantanoo
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ 1.13 Is it a Perl program or a Perl script? PerlFAQ Server Perl Misc 0 04-11-2011 04:00 AM
FAQ 1.13 Is it a Perl program or a Perl script? PerlFAQ Server Perl Misc 0 01-20-2011 11:00 AM
Is it a Perl program or a Perl script? business one way Digital Photography 0 01-05-2008 04:40 PM
Perl 'system' Creates Program That Dies When First C Program Dies Christopher M. Lusardi Perl Misc 3 10-19-2003 11:53 AM
Perl Help - Windows Perl script accessing a Unix perl Script dpackwood Perl 3 09-30-2003 02:56 AM



Advertisments