Thread: executing commands

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    61

    Talking executing commands

    hi, i have a string :

    char* string = "ls -a";

    do i have to extract ls out from the entire string to use execlp/execvp/execl/... command? is there a way to run the command without extracting it?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    do i have to extract ls out from the entire string to use execlp/execvp/execl/... command?
    I think so, and you would also need to construct an array (of the form: "ls", "-a", NULL) to pass the arguments.

    is there a way to run the command without extracting it?
    You could use system() instead.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    String literals should be const char: http://cpwiki.sourceforge.net/Common...kes_and_errors
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Executing DOS commands from inside an image
    By Moony in forum C Programming
    Replies: 6
    Last Post: 03-16-2008, 12:40 PM
  2. Run Error, Commands Executing Simultaneously..
    By MistuRaz in forum C Programming
    Replies: 3
    Last Post: 12-10-2006, 04:10 AM
  3. Executing system commands cross platform
    By markucd in forum C++ Programming
    Replies: 6
    Last Post: 11-04-2005, 08:56 AM
  4. Replies: 1
    Last Post: 03-11-2003, 05:36 PM
  5. Executing shell/dos commands
    By Zaarin in forum C++ Programming
    Replies: 2
    Last Post: 08-28-2001, 10:29 PM