Page 1 of 1

Rsh, Help -piping output back

PostPosted: Tue Jul 31, 2007 7:28 pm
by mcna
Pls
if any1 can help i would very greatful,
i am creating a program, i want to run a command on a remote machine using rsh.

i can use popen to do this, but if the ip address is wrong it hangs 4ever. Not what i want.

so i have desided to use the fork and execl as this means that if rsh hangs i can time out.

but i cant get the rsh output to pipe back, i am expecting the commands from the remote batch file i am running to be to be outputed. Rsh works because i have it create 2 file so i know it has worked, but no output.

using popen i do get output but i dont want it 2 be able 2 hang 4ever.

Thx 4 all ur help

Re: Rsh, Help -piping output back

PostPosted: Wed Aug 01, 2007 5:11 pm
by mcna
i surpose i dont count 2 much as a beginer any more.

i really hope some 1 can help me with this.

2 be honest it isnt basic. so any experenaced user plz help

Re: Rsh, Help -piping output back

PostPosted: Wed Aug 01, 2007 6:33 pm
by William Thompson
mcna wrote:2 be honest it isnt basic. so any experenaced user plz help
Sometimes the people with the answers just are not available....
What platform are you running this shell on and what version of C/C++?

Re: Rsh, Help -piping output back

PostPosted: Wed Aug 01, 2007 6:41 pm
by mcna
2 be honest i dont no,

well i do know i am using ibm's adcd, v1r6 if that helps at all

Re: Rsh, Help -piping output back

PostPosted: Thu Aug 02, 2007 6:15 am
by dick scherrer
Hello,

Before the code issues the popen, would using "ping" do what you need? Ping goes a bit slowly when it cannot reach an ip address, but it does not hang out forever.

Once the ping was successful, then issue the popen.

Re: Rsh, Help -piping output back

PostPosted: Thu Aug 02, 2007 3:40 pm
by mcna
no it wont help, becuase a ping only will tell if the machine is there but i need to know if it has rsh.

i already know there is a machine is there because i connect using ftp to check if the machine is there.

ive been told by another programmer to use the fork/execl method, i use this method for the ftp but rsh it runs the command but no output.

do you know if rsh uses stdout to output on to, or if it uses a different one. the programmer who sed to use the fork/execl method also sed that because rsh is not interactive u parse it commands and it does them (unlike ftp, where more inputs are needed eg user password get), onces it done it dies. meaning that if the rsh end so will that process and the pipe will be broken and the data held in the pipe gone (this is wot me and him think) but i dont no

Re: Rsh, Help -piping output back

PostPosted: Tue Aug 14, 2007 4:38 pm
by mcna
Dont worry

I have done it now,

thats 4 all ur help anyway

Re: Rsh, Help -piping output back

PostPosted: Tue Aug 14, 2007 11:53 pm
by dick scherrer
Good to hear that it is now working.

If would be helpful if you post your solution and then someone else with a similar question might find an answer in what you did.

Re: Rsh, Help -piping output back

PostPosted: Wed Aug 15, 2007 5:34 pm
by mcna
Yeah sure,

it will have 2 be in the next few days.
just recevied a new work machine, and need to setup the machine.

when i am back online and using the mainframe again i will post the code, or at least a verison of it

Re: Rsh, Help -piping output back

PostPosted: Wed Aug 22, 2007 5:17 pm
by mcna
Im very sorry,

i can give people a hand wiv doin this but

i do not own the code, it is not mine to post.
i have been warned if i post any code copied from the project or any other project i will be out of a job.

i can put it in simple terms, first create a pipe(/*pipe name*/) e.g. pipe(fd1);

if ( (pid = fork()) < 0)
{
sprintf(ErrorMessage,"fork error");
return 0;
}
else if (pid > 0)
{ /* parent */

}
else
{ /*child*/

}

then once in to the parent close the input end of the pipe, and in the child close the ouput end.
then make the child put all data from stdout in the pipe.

which then can be read by the parewnt process.

sorry i can be any more detailed, but i can help.

just post ur code and i will try and help