Rsh, Help -piping output back



Help for C/C++ for MVS, OS/390 C/C++, z/OS C/C++ and C/C++ Productivity Tools for OS/390

Rsh, Help -piping output back

Postby mcna » Tue Jul 31, 2007 7:28 pm

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
mcna
 
Posts: 20
Joined: Tue Jul 31, 2007 7:16 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Rsh, Help -piping output back

Postby mcna » Wed Aug 01, 2007 5:11 pm

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
mcna
 
Posts: 20
Joined: Tue Jul 31, 2007 7:16 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Rsh, Help -piping output back

Postby William Thompson » Wed Aug 01, 2007 6:33 pm

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++?
William Thompson
 
Posts: 81
Joined: Sat Jun 09, 2007 4:24 am
Location: Tucson AZ
Has thanked: 0 time
Been thanked: 1 time

Re: Rsh, Help -piping output back

Postby mcna » Wed Aug 01, 2007 6:41 pm

2 be honest i dont no,

well i do know i am using ibm's adcd, v1r6 if that helps at all
mcna
 
Posts: 20
Joined: Tue Jul 31, 2007 7:16 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Rsh, Help -piping output back

Postby dick scherrer » Thu Aug 02, 2007 6:15 am

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.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6269
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Rsh, Help -piping output back

Postby mcna » Thu Aug 02, 2007 3:40 pm

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
mcna
 
Posts: 20
Joined: Tue Jul 31, 2007 7:16 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Rsh, Help -piping output back

Postby mcna » Tue Aug 14, 2007 4:38 pm

Dont worry

I have done it now,

thats 4 all ur help anyway
mcna
 
Posts: 20
Joined: Tue Jul 31, 2007 7:16 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Rsh, Help -piping output back

Postby dick scherrer » Tue Aug 14, 2007 11:53 pm

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.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6269
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Rsh, Help -piping output back

Postby mcna » Wed Aug 15, 2007 5:34 pm

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
mcna
 
Posts: 20
Joined: Tue Jul 31, 2007 7:16 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Rsh, Help -piping output back

Postby mcna » Wed Aug 22, 2007 5:17 pm

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
mcna
 
Posts: 20
Joined: Tue Jul 31, 2007 7:16 pm
Has thanked: 0 time
Been thanked: 0 time


Return to C, C++