You are not logged in.

#1 2012-05-19 10:51:00

Jindur
Member
Registered: 2011-09-29
Posts: 184

execute a command with piping, from a c program [SOLVED]

#include <unistd.h>
main() {
execlp("bash", "bash", "7z", ">", "7z.tmp", NULL);
}

just gives me "incorrect command line". Any ideas?
Pretty hard to google/search for this, I didn't get any usable results, so trying my luck here.

Last edited by Jindur (2012-05-19 11:23:12)

Offline

#2 2012-05-19 10:56:23

Cloudef
Member
Registered: 2010-10-12
Posts: 636

Re: execute a command with piping, from a c program [SOLVED]

try ("bash", "bash", "-c", "7z > 7z.tmp", NULL);
Though executing subshell is not recommended in C, make sure you don't allow user input in.
Or if you do, single quote them and strip additional single quotes.

Last edited by Cloudef (2012-05-19 10:57:29)

Offline

#3 2012-05-19 11:22:51

Jindur
Member
Registered: 2011-09-29
Posts: 184

Re: execute a command with piping, from a c program [SOLVED]

Thanks, that fixed it.

Offline

#4 2012-05-19 13:00:55

lunar
Member
Registered: 2010-10-04
Posts: 95

Re: execute a command with piping, from a c program [SOLVED]

You should replace the subshell invocation with proper piping so that you don't need temporary files anymore.

Offline

#5 2012-05-20 19:33:31

nomorewindows
Member
Registered: 2010-04-03
Posts: 3,408

Re: execute a command with piping, from a c program [SOLVED]

Usually piping into your program usually involves the input or the contents of a file, as if it were being typed in and being processed much the same.


I may have to CONSOLE you about your usage of ridiculously easy graphical interfaces...
Look ma, no mouse.

Offline

Board footer

Powered by FluxBB