Re: [DUG] CreateProcess
This may help: C:\Documents and Settings\Alistercmd /? Starts a new instance of the Windows XP command interpreter CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF] [[/S] [/C | /K] string] /C Carries out the command specified by string and then terminates /K Carries out the command specified by string but remains /S Modifies the treatment of string after /C or /K (see below) /Q Turns echo off /D Disable execution of AutoRun commands from registry (see below) /A Causes the output of internal commands to a pipe or file to be ANSI /U Causes the output of internal commands to a pipe or file to be Unicode /T:fg Sets the foreground/background colors (see COLOR /? for more info) /E:ON Enable command extensions (see below) /E:OFF Disable command extensions (see below) /F:ON Enable file and directory name completion characters (see below) /F:OFF Disable file and directory name completion characters (see below) /V:ON Enable delayed environment variable expansion using ! as the delimiter. For example, /V:ON would allow !var! to expand the variable var at execution time. The var syntax expands variables at input time, which is quite a different thing when inside of a FOR loop. /V:OFF Disable delayed environment expansion. Note that multiple commands separated by the command separator '' are accepted for string if surrounded by quotes. Also, for compatibility reasons, /X is the same as /E:ON, /Y is the same as /E:OFF and /R is the same as /C. Any other switches are ignored. If /C or /K is specified, then the remainder of the command line after the switch is processed as a command line, where the following logic is used to process quote (") characters: 1. If all of the following conditions are met, then quote characters on the command line are preserved: - no /S switch - exactly two quote characters - no special characters between the two quote characters, where special is one of: ()@^| - there are one or more whitespace characters between the the two quote characters - the string between the two quote characters is the name of an executable file. 2. Otherwise, old behavior is to see if the first character is a quote character and if so, strip the leading character and remove the last quote character on the command line, preserving any text after the last quote character. If /D was NOT specified on the command line, then when CMD.EXE starts, it looks for the following REG_SZ/REG_EXPAND_SZ registry variables, and if either or both are present, they are executed first. HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun and/or HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun Command Extensions are enabled by default. You may also disable extensions for a particular invocation by using the /E:OFF switch. You can enable or disable extensions for all invocations of CMD.EXE on a machine and/or user logon session by setting either or both of the following REG_DWORD values in the registry using REGEDT32.EXE: HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\EnableExtensions and/or HKEY_CURRENT_USER\Software\Microsoft\Command Processor\EnableExtensions to either 0x1 or 0x0. The user specific setting takes precedence over the machine setting. The command line switches take precedence over the registry settings. The command extensions involve changes and/or additions to the following commands: DEL or ERASE COLOR CD or CHDIR MD or MKDIR PROMPT PUSHD POPD SET SETLOCAL ENDLOCAL IF FOR CALL SHIFT GOTO START (also includes changes to external command invocation) ASSOC FTYPE To get specific details, type commandname /? to view the specifics. Delayed environment variable expansion is NOT enabled by default. You can enable or disable delayed environment variable expansion for a particular invocation of CMD.EXE with the /V:ON or /V:OFF switch. You can enable or disable completion for all invocations of CMD.EXE on a machine and/or user logon session by setting either or both of the following REG_DWORD values in the registry using REGEDT32.EXE: HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\DelayedExpansion and/or HKEY_CURRENT_USER\Software\Microsoft\Command Processor\DelayedExpansion to either 0x1 or 0x0. The user specific setting takes precedence over the machine setting. The command line switches take precedence over the registry settings. If delayed environment variable expansion is enabled, then the exclamation character can be used to substitute the value of an environment variable at execution time. File and Directory name completion is NOT enabled by default. You can enable or disable file name completion for a particular invocation of CMD.EXE with the /F:ON or /F:OFF switch. You can enable or disable completion for all invocations of CMD.EXE on a machine and/or user logon session by setting either or both of the following REG_DWORD values in the registry using REGEDT32.EXE:
RE: [DUG] CreateProcess
Cmd /c is from the help: Starts a new instance of the Windows XP command interpreter CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF] [[/S] [/C | /K] string] /C Carries out the command specified by string and then terminates /K Carries out the command specified by string but remains You have to be aware when its needed and when it isn't. For instance I usually use ShellExecute, and if the command has the .BAT on the end and the windows assocation for running a .BAT extension is in place then it make the association with CMD itself. Specifying CMD/C will remove any uncertainty. Remember if you run such a command on Windows 9x or ME then you need to use instead COMMAND/C John -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Robert martin Sent: Thursday, 26 October 2006 11:10 a.m. To: [EMAIL PROTECTED]; NZ Borland Developers Group - Delphi List Subject: Re: [DUG] CreateProcess Hi You are the man Laurie. That seems to work great now! btw what does the /c do? Rob Martin Software Engineer phone +64 03 377 0495 fax +64 03 377 0496 web www.chreos.com Wild Software Ltd lbisman wrote: Should that pChar string be 'cmd /c MySQLExport.bat' as it's the command interpreter that usually runs batch files... Laurie.. - Original Message Follows - Hi I am trying to use create process to run a batch file. The batch file exports a MySQL DB to a file. The batch file runs but the file is 0kb however if run that batch file normally (not from CreateProcess) the file is correctly created (about 2MB). The code I am using is shown below, does anyone have any idea as to what I am doing wrong? var proc_info : TProcessInformation; startinfo : TStartupInfo; ExitCode : longword; begin Result := False; // Initialize the structures FillChar(proc_info, sizeof(TProcessInformation), 0); FillChar(startinfo, sizeof(TStartupInfo), 0); startinfo.cb := sizeof(TStartupInfo); // Attempts to create the process if (CreateProcess(Nil, pChar('MySQLExport.bat'), nil, nil, false, NORMAL_PRIORITY_CLASS, nil, pChar(AppDir), startinfo, proc_info) False) then begin // Process created, now s wait till it ends... WaitForSingleObject(proc_info.hProcess, INFINITE); GetExitCodeProcess(proc_info.hProcess, ExitCode); CloseHandle(proc_info.hThread); CloseHandle(proc_info.hProcess); Sleep(5000); //Wait 5secs just to allow any windows cleanup or other to finish if (FileExists(AppDir + BASE_FILE) = True) then begin if (CreateZipFile = True) then begin Result := True; end; end; end; end; -- Rob Martin Software Engineer phone +64 03 377 0495 fax +64 03 377 0496 web www.chreos.com Wild Software Ltd ___ Delphi mailing list Delphi@ns3.123.co.nz http://ns3.123.co.nz/mailman/listinfo/delphi Laurie.. ___ Delphi mailing list Delphi@ns3.123.co.nz http://ns3.123.co.nz/mailman/listinfo/delphi ___ Delphi mailing list Delphi@ns3.123.co.nz http://ns3.123.co.nz/mailman/listinfo/delphi __ NOD32 1.1461 (20060329) Information __ This message was checked by NOD32 antivirus system. http://www.eset.com ___ Delphi mailing list Delphi@ns3.123.co.nz http://ns3.123.co.nz/mailman/listinfo/delphi
Re: [DUG] CreateProcess
Should that pChar string be 'cmd /c MySQLExport.bat' as it's the command interpreter that usually runs batch files... Laurie.. - Original Message Follows - Hi I am trying to use create process to run a batch file. The batch file exports a MySQL DB to a file. The batch file runs but the file is 0kb however if run that batch file normally (not from CreateProcess) the file is correctly created (about 2MB). The code I am using is shown below, does anyone have any idea as to what I am doing wrong? var proc_info : TProcessInformation; startinfo : TStartupInfo; ExitCode : longword; begin Result := False; // Initialize the structures FillChar(proc_info, sizeof(TProcessInformation), 0); FillChar(startinfo, sizeof(TStartupInfo), 0); startinfo.cb := sizeof(TStartupInfo); // Attempts to create the process if (CreateProcess(Nil, pChar('MySQLExport.bat'), nil, nil, false, NORMAL_PRIORITY_CLASS, nil, pChar(AppDir), startinfo, proc_info) False) then begin // Process created, now s wait till it ends... WaitForSingleObject(proc_info.hProcess, INFINITE); GetExitCodeProcess(proc_info.hProcess, ExitCode); CloseHandle(proc_info.hThread); CloseHandle(proc_info.hProcess); Sleep(5000); //Wait 5secs just to allow any windows cleanup or other to finish if (FileExists(AppDir + BASE_FILE) = True) then begin if (CreateZipFile = True) then begin Result := True; end; end; end; end; -- Rob Martin Software Engineer phone +64 03 377 0495 fax +64 03 377 0496 web www.chreos.com Wild Software Ltd ___ Delphi mailing list Delphi@ns3.123.co.nz http://ns3.123.co.nz/mailman/listinfo/delphi Laurie.. ___ Delphi mailing list Delphi@ns3.123.co.nz http://ns3.123.co.nz/mailman/listinfo/delphi