How can I run this command from my Delphi application?
C:\myapppath\appfolder>appname.exe /stext save.txt
I tried the following code:
ShellExecute(0, nil, 'cmd.exe', 'cd C:\myapppath\appfolder', nil, SW_Hide);
ShellExecute(0, nil, 'cmd.exe', 'appname.exe /stext save.txt', nil, SW_Hide);
But it didn’t work. Can anyone provide a solution?
To run a CMD command, you need to use the
/Cflag ofcmd.exe:However, this will create two different sessions, so it will not work. But you can use ShellExecute to run
appname.exedirectly, like so:But you need to specify the filenames properly.
I would do
in case
appname.exeis the current application. Otherwise, replaceApplication.ExeNamewith the full path ofappname.exe.