Executing Dos commands

I want to execute the following line without showing the prompt window in no way.
ShellExecute( Self.Handle, 'open', PChar( 'C:\WINDOWS\COMMAND\COMMAND.COM' ),
                              PChar( '/C DIR > ANYFILE.TXT'),
                              PChar( 'C:\WINDOWS\COMMAND'),
                              SW_SHOWMINIMIZED );
How could I do this?

P.S. I've used all combinations of SW_HIDE or SW_* and none of them give the result i'm looking for.
rarigoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kretzschmarCommented:
hi rarigo,

try this

WinExec('C:\WINDOWS\COMMAND\COMMAND.COM /C DIR > ANYFILE.TXT', SW_HIDE);

hoping there is no typo

meikl
0
rarigoAuthor Commented:
Hi kretzschmar,

    It doesn't matter WinExec, ShellExecute. It's the same. They show you the MS-DOS Prompt Window. The better way so far would be use any of them with the SW_MINIMIZED.


Tchau,
Reginaldo
0
kretzschmarCommented:
hi rarigo,

not by me,
have you tried it ?

meikl ;-)
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

intheCommented:
when i use the sw_hide const in winexec etc it is hidden ok so dunno why not for you but what about trying createprocess instead:


var
  tsi: TStartupInfo;
  tpi: TProcessInformation;
  code : DWORD;
  comspec : array[0..511] of char;
  cmd : string;
 
begin
  FillChar(comspec, sizeof(comspec), 0);
  GetEnvironmentVariable('comspec', comspec, sizeof(comspec));
  // comspec gets the path to the command shell, command.com or cmd.exe   // I use this to execute a dos command. It is not required to execute a windows app
  cmd := comspec+' /c dir > anyfile.txt';
 
  FillChar(tsi, SizeOf(TStartupInfo), 0);
  tsi.cb := SizeOf(TStartupInfo);
  tsi.wShowWindow := SW_HIDE;
  tsi.dwFlags := STARTF_USESHOWWINDOW;
 
  if CreateProcess(nil, PChar(cmd), nil, nil, True, 0, nil, nil, tsi,tpi) then
  begin
    WaitForSingleOject(tpi.hProcess, INFINITE);
    GetExitCodeProcess(tpi.hProcess, code);  // exit code value
  end;
end;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rarigoAuthor Commented:
Hi kretzschmar and inthe,

   Yes, I've tried WinExec and Createprocess with SW_HIDE flag before posting my question to this forum and
does not work. I still see the DOS-Prompt window poping up on my screen.
As I've told before the better way till now proved to be use SW_SHOWMINIMIZE because all you'll see is a dosprompt window minimized on taskbar while command is running.
For a fast command like DIR it's not that bad. But what if I execute a dir /s command?


Tchau,
Reginaldo
0
she3i3iCommented:
Listening...
0
rarigoAuthor Commented:
   Well. Let me close this question because it's bothering me this open question and i'll accept inthe comments as an answer because he tried it a little harder even though as I've told I had experimented all these before posting the question to this forum.



Tchau,
Reginaldo
0
rarigoAuthor Commented:
  I've already made a comment to this. I'm giving a B to keep your average.
0
intheCommented:
?
thanks for the points but id prefer if we had found the answer..
is it still not working?
0
rarigoAuthor Commented:
Hi Inthe,

   Not yet. I kinda of gave it up for a while maybe sometime in the future i'll think of that.

    See ya.

Tchau,
Reginaldo
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.