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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using start command with system(); doesn't work 1

Status
Not open for further replies.

DarkDante

IS-IT--Management
Nov 17, 2003
7
US
Please help me. I'm trying to write a script that calls several external windows to pop-up and I'd like to be able to differentiate them by giving the title bars specific names. The command I'm trying to run creates the correct name in the title bar but doesn't execute the command. My code is as follows:

#$IPSCHEME is a predefined variable
#containing an IP Address string
#
#$CID is a predefined variable
#containing a Center ID

system("start \"Pinging Router with IP of: $IPSCHEME\" ping router.$CID.af.com -t");

The window is correctly labeled using my variables, however; the command is not executed. I get a command prompt window with a c:\ prompt.
 
Here is the full script. I'd also like to know how to remove the "[" and "]" from the IP Address information all at the same time. Currently I've got it separated on two lines because I couldn't figure it out.

system("cls");
print("Alpha Code: ");
$CID=<stdin>;
chop($CID);
$CID=~tr/a-z/A-Z/;
open(DATA, "ping router.$CID.af.com |grep router |awk 3 |");
$IPSCHEME=<DATA>;
$IPSCHEME=~s/\[//;
$IPSCHEME=~s/\]//;
exec("start \"Pinging the $CID Router at IP\: $IPSCHEME\" ping router.$CID.af.com -t");
 
I'm really sorry but i have no experience in pinging routers... can you use the following method of executing a system command - i.e. backticks? Sorry if i'm barking up the wrong tree!

Code:
[b]#!/usr/bin/perl[/b]

$IPSCHEME = '192.168.0.2';

print `ping -c 3 $IPSCHEME`;


Kind Regards
Duncan
 
this will remove the square brackets...

Code:
[b]#!/usr/bin/perl[/b]

$IPSCHEME = '[192].[168].[0].[2]';

[red][b]$IPSCHEME =~ s/(\[|\])//g;[/b][/red]

print "I.P. address after removal of square brackets... $IPSCHEME\n";

print `ping -c 3 $IPSCHEME`;


Kind Regards
Duncan
 
regex explaination...

(this[red]|[/red]or this)

both square brackets must be escaped with a backslash or the regex will think you are describing a 'class'

[0-7d-k] - this is an example of a class which describes all numbers between zero and seven, and all lower case characters between 'd' and 'k'

hope this is of some use!


Kind Regards
Duncan
 
Thanks duncdude! Your information helped me with the "[]" substitutions.

I'm still having issues with the "start" command. If you open up an msdos prompt and type the following:

start "Pinging 192.168.0.1" ping 192.168.0.1 -t

It will open up an additional command window with the menu title of "Pinging 192.168.0.1" and the content of the window will be the continual ping for that IP Address. My problem is that I want perl to run this command and give the window the correct title.

If I use:
system("start \"Ping 192.168.0.1\" ping 192.168.0.1 -t");

It opens up the additional window and gives it the correct name but never executes the "ping 192.168.0.1 -t" portion of the command.

I've also tried using:
exec("start \"Ping 192.168.0.1\" ping 192.168.0.1 -t");

but the program just exits and doesn't even open the additional window.
 
ah! DOS - i'm afraid i'm on a UNIX box and can't test this out

have you tried...

print `start "Pinging 192.168.0.1" ping 192.168.0.1 -t`;


Kind Regards
Duncan
 
Well thanks for the effort duncdude. At least you got 1 of 2 items fixed! I appreciate the help.

I attempted your print statement and it displayed the command syntax on my screen instead of running it. I'll just wait and see if any other Microsoft Windows Perl programmers can answer my initial question.

Take care! I gave ya a star for your substitution post.
 
Thanks dude!

You are using backticks and not single speech marks I assume...


Kind Regards
Duncan
 
Good call, I was using single speech marks. That wasn't the fix though. I've actually figured it out on my own.

I forgot to chop my data string for $IPSCHEME in my code above. There was apparently a carriage return at the end of my code and that was causing the rest of the command string to be nullified.

Once I added the line:
chop($IPSCHEME);

just below
$IPSCHEME=<DATA>;

it worked just fine.

Thanks for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top