Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 05-17-2004, 02:04 AM   #1
LQ Newbie
Registered: May 2004
Posts: 23

Rep: Reputation: 15
Question run shell command inside of c code?

in one directory, i have cpc.c and cource file

cpc.c is :
system("/bin/sh -c cp source dest");

i want copy source file to dest file, but there is no dest file.
when i execute cpc by type ./cpc, there is something error like "cp: missing file arguments".

how about that?

Old 05-17-2004, 02:24 AM   #2
LQ Newbie
Registered: Feb 2004
Posts: 16

Rep: Reputation: 0
The correct prog is following
cpc.c is :
system("/bin/sh \"-c cp source dest\"");

as -c option take the single input string as argument in multiple strings must be quoted
Old 05-17-2004, 10:04 AM   #3
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 110Reputation: 110
Why so difficult?
According to "man system":
system() executes a command specified in string by calling /bin/sh -c string, and returns after the command has been completed.
So if system() already will start "sh -c" for you, why start another one?
#include <stdlib.h>

int main()
        system("cp source dest");
        return 0;


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
execute shell command inside of c code? khucinx Programming 6 10-26-2010 09:30 PM
Problem executing mv command inside shell script pablogosse Linux - General 7 12-16-2009 12:21 PM
execute shell command inside of tcl file khucinx Programming 1 07-05-2004 01:29 PM
how do I run a command from inside a c++ program? exodist Programming 1 04-06-2004 04:34 PM
how to invoke a linux command inside a java code ? kusum Linux - Software 2 11-23-2003 01:19 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:01 PM.

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