hi,
Can I use a popen to ssh a command to another box and then use a Unix echo command to print output to my present console..?
like this
Thnk u,Code:char exe[]="\/usr\/bin\/ssh -v HOSTNAME \";perl -e 'print \" Hello world \"' ";
hi,
Can I use a popen to ssh a command to another box and then use a Unix echo command to print output to my present console..?
like this
Thnk u,Code:char exe[]="\/usr\/bin\/ssh -v HOSTNAME \";perl -e 'print \" Hello world \"' ";
sure, just send "ssh machine echo \"Hello, World\"" to the machine.
You don't need to do \/ - only \ needs an extra \.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
I tried the simple echo command first but its not working...some how the echo doesnt diosplay on present console.
Doesnt work even now....Code:char exe[]="\/usr\/bin\/ssh -v HOSTNAME \" ;echo \" Hello world \" \" ";
Describe what happens...
And you still have unnecessary backslashes in your string - it probably doesn't matter, but it tells me you didn't read my post very well.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Hi like I was saying I tried without the qoutes too....
Actually this is what I am trying.....
As I showed above....I get the list of files from the other box....Code:char exe[]="\/usr\/bin\/ssh -v HOSTNAME \";echo printing file ; ls -ltr ";
But I dont get the echo output.....
any idea what I am missing..../
Not sure I understand what you are saying: Are you saying you get the result of ls, but not from echo, or are you saying that you get the result of ls on the local machine, and no result from ssh?
What happens if you just doon a command line?Code:ssh hostname echo Hello World
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
At the same time if I run this command from the command line ....
It get the reply back as 'Hello world'Code:ssh hostname echo Hello World
"...Are you saying you get the result of ls, but not from echo..."
As you said....I get the result of the ls...but not from echo.
And what do you get if you do:
and pass "exe" to system()?Code:char exe[]="/usr/bin/ssh HOSTNAME echo \"Hello world \" ";
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
I get the echo output now.Code:char cmd[400]; sprintf(cmd,"\/usr\/bin\/ssh -v HOSTNAME \";echo printing file ; ls -ltr ";); char exe_str[]=system( cmd ); if((ptr = popen(exe_str, "r")) == NULL) perror("Couldn't open pipe"); if(fgets(data, 256, ptr) == NULL) { } pclose(alp); while (fgets(data, 100, ptr) != NULL) { printf("%s ",line); }
But I have a new problem....
I get the system( cmd) ; output on the console even before the printf command in the fgets statement....
(please let me know if I was clear)
Really, you do have to CHOOSE whether you want to use popen or system - not both. Also, you should get a warning for "converting integer to string" for the system line in this snippet
And since exe_str is very unlikely to point to a valid string and the commend executes "OK" [since it is zero -> NULL, it will probably be a NULL pointer, but whatever system returns, it is VERY unlikely to be a valid string pointer in your application]. So popen() either fails or crashes.Code:char exe_str[]=system( cmd ); if((ptr = popen(exe_str, "r")) == NULL)
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.