PDA

View Full Version : Executing commandline commands



NecroDOME
15-04-2008, 05:14 PM
Hi,

I'm trying to execute command line commands. This would be nice for my console.

So far I got it working that I can execute application and batch files. Console output is redirected to my in-game console. The only thing that doesn't work is executing commands like "dir" and "cd". (If I put these in a .bat file, it works fine)

thnx

ps: this is how you capture console output pipeline: http://delphi.about.com/cs/adptips2001/a/bltip0201_2.htm

marcov
14-05-2008, 08:29 AM
Internal shell commands need to be executed with the shell. That's why it works with batchfiles.

Executing with shell looks like cmd /c "dir".

You can do this by using

executeprocess(getenvironmentstring('COMSPEC').['/c','dir']);

Also, have a look at the process unit (I have that one also running under Delphi, it is easy to port).

NecroDOME
17-05-2008, 09:51 AM
Thanks :)

I will try that soon.

Thanks for you comment.

NecroDOME
17-05-2008, 10:18 AM
thanks, I tried some things, no I work with the prefix 'cmd /C'. You pushed my in the right direction. It works now :)

marcov
23-05-2008, 09:31 AM
thanks, I tried some things, no I work with the prefix 'cmd /C'. You pushed my in the right direction. It works now :)

getenvironmentvariable('COMSPEC') will return cmd on windows NT/2k/XP/vista and command.com on win9x and dos. (that don't have cmd.exe), and some dos shell under OS/2 too.

IOW, it is slightly more portable than hardcoding it

NecroDOME
23-05-2008, 03:31 PM
It's only for debuggin purpose, checking some thing in-game, nothing spectacular that will be in the production code.