executing commands

This is a discussion on executing commands within the C Programming forums, part of the General Programming Boards category; hi, i have a string : char* string = "ls -a"; do i have to extract ls out from the ...

  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
    21,310
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,413
    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, 03:10 AM
  3. Executing system commands cross platform
    By markucd in forum C++ Programming
    Replies: 6
    Last Post: 11-04-2005, 07:56 AM
  4. Replies: 1
    Last Post: 03-11-2003, 04:36 PM
  5. Executing shell/dos commands
    By Zaarin in forum C++ Programming
    Replies: 2
    Last Post: 08-28-2001, 10:29 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21