Thread: passing variable to UNIX command

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    2

    passing variable to UNIX command

    Hi,
    I trying to pass a variable to some unix commands and I'm not sure how to do it:
    Example:

    char *string_ptr;
    char unix_cmd[200];

    char unix_string1[]="echo ";
    char unix_string1[]=" | cc=`grep -a \"ControlID\"| cut -c 375-378`";


    main( ArsCSXitPrepExit *prep, char *argv[] )
    {
    int rc;
    string_ptr=strcat(unix_cmd,unix_string1);
    string_ptr=strcat(unix_cmd,argv[1]); <<<<< variable to pass
    string_ptr=strcat(unix_cmd,unix_string2);
    system(string_ptr);

    I want the output to UNIX to look like:

    echo $something | cc=`grep -a "ControlID" | cut -c 375-378`

    Then I want $cc passed back to the C program.

    Thanks.

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    First off get the Unix command right before trying to create one through catenation.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. Variable Array Size From Command Line Argument?
    By Cell in forum C Programming
    Replies: 6
    Last Post: 03-30-2009, 09:08 PM
  3. #define variable from main() command
    By transgalactic2 in forum C Programming
    Replies: 17
    Last Post: 01-21-2009, 07:22 AM
  4. passing an ifstream variable
    By axon in forum C++ Programming
    Replies: 1
    Last Post: 04-03-2004, 08:22 PM
  5. unix command
    By axon in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 02-22-2004, 12:35 PM