Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
P is for Practical
 
PerlMonks  

system call works on *nix not NT

by Unholy One (Initiate)
on Jul 01, 2004 at 10:46 UTC ( #371032=perlquestion: print w/ replies, xml ) Need Help??
Unholy One has asked for the wisdom of the Perl Monks concerning the following question:

Learned brothers, I have a humble perl script which runs fine when run on unix against other unixes. When run on an w2k box against the unix box it fails without presenting an error message: perl -e 'system("rsh hostname -l username -n \"touch test\"")'; I'm running active perl build 810 on the w2k box. I've trawled the web and the monastry cellars without luck. Please assist - I'm sure this is a realy dumb-ass mistake I'm making!

Comment on system call works on *nix not NT
Re: system call works on *nix not NT
by gaal (Parson) on Jul 01, 2004 at 10:56 UTC

    1. Make sure you have an RSH.EXE in your path. Better, use a full pathname.

    2. There's a chance you're bitten by shell quoting. Try using the LIST variant of system:
    system ($RSH, qw/hostname -l username -n/, "touch test")  == 0 or die "system: $?";

    3. Check the return value of system!

Re: system call works on *nix not NT
by beable (Friar) on Jul 01, 2004 at 11:19 UTC
    Does rsh hostname -l username -n \"touch test\" work from a DOS-box or a shell on the w2k box?
      Thank you for your thoughts: I have now added the full path to rsh as suggested. It does not appear to have changed anything. I'm still looking at the shell quoting idea. Yes, I can run the rsh stuff from the command line on the w2k box just fine. Its only when I try and do it from the perl that things go wrong!
        You should do what gaal says, and check the return value from system, and check the $? variable (see perlvar, and use the $! variable if system() doesn't return 0. Also, you might want to consider using the Net::Rsh or Net::SSH modules from CPAN.
Re: system call works on *nix not NT
by arden (Curate) on Jul 01, 2004 at 14:42 UTC
    This sounds like a configuration issue on the unix host(s) to me. Have you made sure that there is an entry in the /etc/rhosts or $userid/.rhosts file allowing any user from the from the windows machine to rsh into the unix host as that username? The exact filename for the configuration file may differ for your specific operating system.

    One way to test it: can you execute the rsh hostname -l username -n "touch test" command from a dos-prompt successfully? If not, the Perl won't be able to either.

    - - arden.

Re: system call works on *nix not NT
by Scarborough (Hermit) on Jul 01, 2004 at 15:50 UTC
    Thinking a little out of the box, and your dumb arse comment made me think simple and I have no idea how to use rsh so I tried with dir using the following.
    perl -e 'system("dir")' #failed perl -e 'system(\"dir\")' #failed perl -e system("dir") #worked perl -e system(\"dir\") #worked
    If you posting is exactly what you type, could this be the be the answer?

      Oh yeah, of course that's what I was trying to remember. Quoting is different on DOS boxes. Try this instead:

      perl -e "system(\"rsh hostname -l username -n \"touch test\"\")"

      From memory (sorry I don't have a Windows box to test on), single quotes don't work very well in the MSDOS prompt. So you need to use double quotes instead. And then you need to escape the double quotes inside the double quotes, or else use single quotes which Perl can handle:

      perl -e "system('rsh hostname -l username -n \'touch test\'')"

Re: system call works on *nix not NT
by Anonymous Monk on Jul 01, 2004 at 15:52 UTC
    One thing you might try is makeing a batch file such as

    :: rsh.bat echo %1 >> C:\look.txt echo %2 >> C:\look.txt ...
    Then try the perl script against the batch file instead of the rsh exe. This should at least confirm that the program is getting the parameters. Aside from that, as others have said, I would try using rsh from the same working directory from the command line and test it there as well.
      Brothers, I am supremely impressed and very greatfull for your time. Two of the mentioned approaches worked. The rsh perl module worked well, as did perl -e "system('rsh hostname -l username -n \'touch test\'')" Thank you, i've realy enjoyed my visit to the monastry...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://371032]
Approved by tinita
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (12)
As of 2014-04-23 22:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (556 votes), past polls