Delphied 0 Posted 21 hours ago I am trying to execute a command line program located in a folder that the user sets and it doesn't appear to work. The Windows command is as follows: C:\Users\<username>\Desktop\Winlibimobile\idevice_id.exe > C:\Users\<username>\Desktop\Logs\idevice_id.log When I enter this in the command line I get the output in the idevice log file in the location specified. But when I user shellexecute it does not work. procedure TfrmMdp.btnExtractClick(Sender: TObject); var DeviceIdCmd : string; begin DeviceIdCmd := ExePath + '\idevice_id.exe > ' + LogPath + '\idevice_id.log'; ShowMessage(DeviceIdCmd); //ShellExecute(0, nil, 'cmd.exe', PChar(DeviceIdCmd), nil, SW_HIDE); <---this also did not work ShellExecute(Handle ,'open', PChar(DeviceIdCmd), '', nil, SW_SHOWNORMAL); end; Is there something I'm missing? Thanks in advance! Share this post Link to post
Delphied 0 Posted 20 hours ago I found a crude work around. I wrote a batch script with the needed command and used DosCommand to execute it and it worked! Thinking I could create the batch script in code, so user selection for directories are correct and execute that then delete the batch script so it doesn't interfere with the next run. Share this post Link to post
Remy Lebeau 1510 Posted 14 hours ago (edited) Command line redirection is performed by the command line interpreter Try adding the /C parameter when invoking cmd.exe directly: DeviceIdCmd := '/C ' + AnsiQuotedStr(ExePath + '\idevice_id.exe', '"') + ' > ' + AnsiQuotedStr(LogPath + '\idevice_id.log', '"'); ShellExecute(0, nil, 'cmd.exe', PChar(DeviceIdCmd), nil, SW_HIDE); Alternatively, use CreateProcess() to execute idevice_id.exe directly and capture it's output to write to the log file yourself: Creating a Child Process with Redirected Input and Output Edited 1 hour ago by Remy Lebeau Share this post Link to post
David Heffernan 2383 Posted 11 hours ago As a broad rule, you should never call ShellExecute. It's long since been replaced by ShellExecuteEx. The only reason you need to know why, is that ShellExecute doesn't report errors correctly. ShellExecuteEx does. And in this case, as in so many cases, as Remy already pointed out, CreateProcess is correct. Whenever you are creating a new process, you use CreateProcess and not ShellExecuteEx. The latter is for executing shell verbs. Share this post Link to post
Delphied 0 Posted 3 hours ago Excellent, thanks all I will give it a shot and see how it goes! Really appreciate the help! Share this post Link to post