Thread: running .exe file with CreateProcess

  1. #1
    Registered User
    Join Date
    Oct 2018
    Posts
    10

    running .exe file with CreateProcess

    so im trying for a couple of days to run a simple .exe file (that creating a simple text file) using the function createprocess. i put the path that i want to run, in the cmd, as the second input for the function. the debugger says that the function succeed but the txt file does not apear anywhere. how can i know whats been happening?
    i tried so many things like using TCHAR and backslashes for the path but none solved it.
    i can add my thread function code if someone would like to observe it.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,657
    Yes, you need to post your code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2018
    Posts
    10
    Code:
     DWORD WINAPI thread_function(LPVOID lpParam) 
    {
    	TCHAR *t;
    	int command_line_out = 100;
    	tests_line *test = (tests_line*)lpParam;
    	char command_line[MAX_LINE_LEN];
    	TCHAR *fixed_exe_line[MAX_LINE_LEN];
    	//connect_file_name_and_args(test, &command_line); // creating the command line "text1.exe hello"
    	//printf("\n%s\n", command_line);
    	*fixed_exe_line = _T("\"C:\\Users\\sagic\\Desktop\\Example1 test1.exe\" hello");
    	STARTUPINFO start_info ;
    	PROCESS_INFORMATION process_info ;
    	ZeroMemory(&start_info, sizeof(STARTUPINFO));
    	ZeroMemory(&process_info, sizeof(PROCESS_INFORMATION));
    	DWORD wait_code;
    	if( !CreateProcess(NULL,fixed_exe_line , NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &start_info, &process_info))
    	{
    		printf("%d", GetLastError());
    		printf("create process failed");
    		return ERROR;
    	}
    	
    	wait_code = WaitForSingleObject(process_info.hProcess,INFINITE);
    
    	if (WAIT_OBJECT_0 != wait_code)
    	{
    		printf("Error when waiting\n");
    		return ERROR;
    	}
    	CloseHandle(process_info.hThread);
    	CloseHandle(process_info.hProcess);
    }

    i want to add that if i run the process outside the thread function it does run test1.exe.

  4. #4
    Registered User
    Join Date
    Dec 2017
    Posts
    1,126
    bInheritHandles should (presumably) be TRUE.
    And lpApplicationName should probably not be blank.
    start_info needs to have it's size field set. You can zero it and set the size field like this:
    Code:
    STARTUPINFO start_info = {sizeof start_info} ;
    It the name of your executable really "Example1 test1.txt"? Or should there be a \\ between those two words?
    The best argument against democracy is a five minute conversation with the average voter. - Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MinGW gcc: error: CreateProcess: No such file or directory
    By stahta01 in forum Windows Programming
    Replies: 0
    Last Post: 02-05-2014, 06:42 PM
  2. Running an EXE file
    By peckitt99 in forum C++ Programming
    Replies: 2
    Last Post: 09-13-2007, 02:49 AM
  3. running an external exe file
    By cloudy in forum C++ Programming
    Replies: 4
    Last Post: 06-06-2005, 12:55 AM
  4. running exe file
    By majoub in forum C Programming
    Replies: 1
    Last Post: 04-24-2005, 02:56 PM
  5. running a external file
    By krappykoder in forum C++ Programming
    Replies: 5
    Last Post: 06-14-2002, 07:19 PM

Tags for this Thread