Thread: system("..."); command

  1. #1
    Unregistered
    Guest

    system("..."); command

    how do I put a variable in the end of this command.
    system("command");
    An example woud be: system ("ping") + IP;

    yhx

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    do conversions of one type or another until you get a single string of input. then use that in the system command.

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    you go like this:

    Code:
    char blah1[10];
    int blah2[10];
    char command[20];
    
    blah1 = ping;
    blah2 = 127.0.0;
    
    strcat(command, blah1);
    strcat(command, blah2);
    
    system(command);
    THIS CODE IS UNTESTED, BUT IT IS SOMETHING ALONG THE LINES OF THAT
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  4. #4
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    Use sprintf.

    char szBuffer [100] ;
    int IP = 127.0.0.1;
    sprintf(szBuffer, "ping %d", IP) ;
    system(szBuffer);

    Remember to include stdio.h

  5. #5
    Registered User
    Join Date
    May 2002
    Posts
    63
    This is similar to OkieSmokies example:

    try this:

    char *ipaddr = new char[11];
    char *ping = "ping ";
    cin.getline(ipaddr, 10, '\n');
    strcat(ping, ipaddr);
    system(ping);
    tudehopet uses Borland Compiler 5.5
    and Visual C++ 6.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. problem with "touch" command in c program
    By Moony in forum C Programming
    Replies: 10
    Last Post: 08-01-2006, 09:56 AM
  3. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  4. Ping problem
    By bladerunner627 in forum C++ Programming
    Replies: 12
    Last Post: 02-02-2005, 12:54 PM
  5. exe files in -c- language
    By enjoy in forum C Programming
    Replies: 6
    Last Post: 05-18-2004, 04:36 PM