2

I want to execute the following command from my C program:

ssh -t -t root@192.168.3.21 "export LINES=40;export COLUMNS=124;export TERM=xterm;$SHELL -i" 0 < t_in 1 > t_out

If I am using system call as in:

system("ssh -t -t root@192.168.3.21 \"export LINES=40;export COLUMNS=124;export TERM=xterm;$SHELL -i\" 0<t_in 1>t_out");

that works fine. But I need to get the PID of the SSH process, so I have to use execlp.

What I tried so far is:

  pid = fork();
  if(pid == 0) {
     fd_in = open("td_in", O_RDWR | O_NONBLOCK);
     dup2(fd_in, 0);
     close(fd_in);
     fd_out = open("td_out", O_RDWR | O_NONBLOCK);
     dup2(fd_out, 1);
     close(fd_out);
     execlp("ssh", "ssh", "-t", "-t", "root@192.168.3.21", "\"export LINES=40;export COLUMNS=124;export TERM=xterm;$SHELL -i\"", 0); 
  } else {
     // not important here
  }

When running this It goes to SSH login and after introducing password I get the error:

bash:export LINES=40;export COLUMNS=124;export TERM=xterm;/bin/bash -i: No such file or directory. Connection to 192.168.3.21 closed.

t_in and t_out are some fifo's (named pipes)

My question is what should be the correct execlp call to execute the above command. Thanks

1 Answers1

0

You can try removing the escaped double quotes in the argument of the ssh command.

execlp("ssh", "ssh", "-t", "-t", "root@192.168.3.21", "export LINES=40;export COLUMNS=124;export TERM=xterm;$SHELL -i", 0); 

They are needed in the 'system' version because the line is processed by the shell, but that is not the case in the 'execcp' version.

damienfrancois
  • 52,978
  • 9
  • 96
  • 110