LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   execl function with pipe (https://www.linuxquestions.org/questions/programming-9/execl-function-with-pipe-4175500820/)

chesschi 04-07-2014 02:23 AM

execl function with pipe
 
I am trying to fork a child process and use execl to execute sftp command. How can I run the following command using execl ?

Code:

echo "put <filename>" | sftp -i <private_key> <username>@password
Many thanks!

pan64 04-07-2014 03:42 AM

see man page of execl, you will see:
Quote:

The exec() family of functions replaces the current process image with a new process image.
furthermore:
Quote:

The const char *arg and subsequent ellipses in the execl(), execlp(), and execle() functions can be thought of as arg0, arg1, ..., argn. Together they describe a list of one or more pointers to null-terminated strings that represent the argument list available to the executed program.
You can see, pipe is not allowed.

Therefore you need to write a small script to implement what you need and execl that script.

chesschi 04-07-2014 07:46 AM

Quote:

Originally Posted by pan64 (Post 5148005)
you need to write a small script to implement what you need and execl that script.

Thanks! It works

NevemTeve 04-08-2014 11:18 PM

fork(2) and pipe(2) are you friends (or system(3))


All times are GMT -5. The time now is 10:44 PM.