LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-07-2014, 02:23 AM   #1
chesschi
Member
 
Registered: May 2011
Posts: 41

Rep: Reputation: 0
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!
 
Old 04-07-2014, 03:42 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
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.
 
1 members found this post helpful.
Old 04-07-2014, 07:46 AM   #3
chesschi
Member
 
Registered: May 2011
Posts: 41

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by pan64 View Post
you need to write a small script to implement what you need and execl that script.
Thanks! It works

Last edited by chesschi; 04-07-2014 at 08:01 AM.
 
Old 04-08-2014, 11:18 PM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
fork(2) and pipe(2) are you friends (or system(3))
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
incompatible implicit declaration of built-in function ‘execl’ ? ? ? jiikka Linux - General 3 05-07-2014 03:09 PM
Windows Spawnl (nowait) like function in Linux... How to use Execl function? cheranj Programming 2 09-15-2011 08:01 PM
read and pipe function dummyagain Programming 13 09-24-2003 10:36 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration