system call works on *nix not NT
Unholy One
created: 2004-07-01 06:46:12
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!
Re: system call works on *nix not NT
created: 2004-07-01 06:56:06

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
created: 2004-07-01 07:19:05
Does rsh hostname -l username -n \"touch test\" work from a DOS-box or a shell on the w2k box?
Re^2: system call works on *nix not NT
created: 2004-07-01 07:43:05
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!
Re^3: system call works on *nix not NT
created: 2004-07-01 08:03:40
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
created: 2004-07-01 10:42:23
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
created: 2004-07-01 11:50:41
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?
Re^2: system call works on *nix not NT
created: 2004-07-01 18:13:56

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
created: 2004-07-01 11:52:23
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.
Re^2: system call works on *nix not NT
created: 2004-07-02 04:28:25
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...

perlmonks.org content © perlmonks.org and Anonymous Monk, arden, beable, gaal, Scarborough, Unholy One

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03