Thread: CreateProcess() + Command Line

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    55
    Quote Originally Posted by IndioDoido View Post
    i really want to use CreateProcess().
    To send commands to cmd from the command line, you must use either the "/C" or "/K" switches. Look at "help cmd". So your call to runScripts would be e.g.:
    Code:
    runScripts( " /K echo howdy");
    You are essentially re-implementing "system" as this is pretty much what it does.

  2. #2
    Registered User IndioDoido's Avatar
    Join Date
    Apr 2007
    Posts
    194
    Salem: i'm using named pipes to send the scripts in a string to the server. How do i send a file through a named pipe?

    hi nucleon: i tried your method (/C and /K) with these CreateProcess(), but they didn't work

    Code:
    CreateProcess(NULL, (LPSTR) str, NULL, NULL, 0, 0, NULL, NULL, &si, &pi);
    CreateProcess("C:\\Windows\\System32\\cmd.exe", (LPSTR) str, NULL, NULL, 0, 0, NULL, NULL, &si, &pi);
    "Artificial Intelligence usually beats natural stupidity."

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    55
    Quote Originally Posted by IndioDoido View Post
    i tried your method (/C and /K) with these CreateProcess(), but they didn't work
    This works for me:
    Code:
    int main()
    {
        STARTUPINFO si = {sizeof(STARTUPINFO)};
        PROCESS_INFORMATION pi;
        CreateProcess( "C:\\Windows\\System32\\cmd.exe",
                       " /K echo test > test2.txt",
                       NULL, NULL, 0, 0, NULL, NULL, &si, &pi);
    }

  4. #4
    Registered User IndioDoido's Avatar
    Join Date
    Apr 2007
    Posts
    194
    i've managed to run the script like this:
    Code:
    CreateProcess(NULL, "cmd /C echo test > c:\test.txt", NULL, NULL, 0, 0, NULL, NULL, &si, &pi))
    What are the differences?
    "Artificial Intelligence usually beats natural stupidity."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. CreateProcess with arguments
    By Niara in forum Windows Programming
    Replies: 14
    Last Post: 09-08-2007, 05:41 AM
  2. CreateProcess with Resource of executable, not the Filename
    By Ktulu in forum Windows Programming
    Replies: 4
    Last Post: 11-04-2006, 01:07 AM
  3. question on CreateProcess() redirection
    By ac251404 in forum Windows Programming
    Replies: 13
    Last Post: 07-18-2006, 11:06 AM
  4. CreateProcess
    By Unregistered in forum Windows Programming
    Replies: 3
    Last Post: 05-12-2002, 06:45 AM
  5. CreateProcess()
    By Newfie in forum C++ Programming
    Replies: 2
    Last Post: 05-07-2002, 07:31 AM