I was able to set up a CreateProcess to launch console applications without problems.

However, I'm stumped when trying to access built-in console commands (such as del and cd).

If I use "del thisfile.exe" from CreateProcess, the console can't find the "del" application.
If I use "console /c del thisfile.exe", it crashes my program.

I've seen code that uses the C system function (hla.exe does this) and they seem to have no problem accessing built-in console commands. Does anyone have a working code sniplet on how to do this in HLA ... or do I have to code all these commands internally (argh!) ?
Posted on 2004-04-04 22:40:17 by Kain
surely its cmd.exe that you're trying to shell to
so the createprocess would be something like

"cmd /c del filename.ext"

yep just tested that via start->run->"cmd /c dir /s"

worked fine, the commands arent built in 'console' commands, i think you confused yourself a little there.. they're essentially dos commands, built into cmd.exe (the command shell for 2k/xp/nt) or command.com (for 9x or below)

hope that helps
Posted on 2004-04-04 23:05:33 by evlncrn8
Yes, yes. my typo there.

On my system, its command.com and that's what I have in my program (not console as I stated in my first post).

I actually have "command /c del filename.ext"

It works for me too when typed from the command line. However, it doesn't work when I send that string through CreateProcess.
Posted on 2004-04-04 23:13:17 by Kain
if you just want to delete a file, why not use the DeleteFileA api? ;)
Posted on 2004-04-05 02:30:26 by evlncrn8
Because DeleteFileA doesn't have wildcards :)
Posted on 2004-04-05 10:21:13 by Kain
Okay, I figured out my error. Seems like I had to type the extension for command.com.

"Command.com /c del *.*"



Now a question for Win NT + users. Does your system also have command.com or is that totally removed in favor of cmd.exe?

I'm asking for compatibility reasons.
Posted on 2004-04-05 15:50:35 by Kain
its cmd.exe on 2k/xp/nt systems, and your use of del *.* i do find somewhat worrying, just what are you up to? ;p
Posted on 2004-04-05 18:43:03 by evlncrn8
Mwahaahaa! :grin: <-- I was going for evil grin, but alas, that smilie is not available.


I'm fooling around with a make-script processor. I know what your thinking... "not another make program?!", but it's more of a demo project for a larger project i'm working on piece by painful piece.

I've got the basic engine working (processing macros, jumps, processing dependencies, launching programs) except for the ability to process dos commands like cd and del. Now I'll be able to fix that nagging problem.
Posted on 2004-04-05 19:43:49 by Kain

its cmd.exe on 2k/xp/nt systems


Theres a command.com on NT systems as well :)

Anyway, I suggest using GetEnvironmentVariable("COMSPEC") to get the command interpreter name and path
Posted on 2004-04-06 15:28:25 by Morris
If you can, stay away from cmd.exe / command.com, though... and if you must, be sure to encapsulate it in a single system() or doscommand() (or whatever you want to call it) call, so it's very little code to change if you need to support some future system without cmd/command.
Posted on 2004-04-06 15:49:57 by f0dder



Theres a command.com on NT systems as well :)

Anyway, I suggest using GetEnvironmentVariable("COMSPEC") to get the command interpreter name and path


Yes, this is a much better way, thanks :)

Now I have a problem trying to execute the cd command. Every other command (del, mkdir, dir, etc) seems to work except for cd.
Posted on 2004-04-06 15:55:50 by Kain

If you can, stay away from cmd.exe / command.com, though... and if you must, be sure to encapsulate it in a single system() or doscommand() (or whatever you want to call it) call, so it's very little code to change if you need to support some future system without cmd/command.


Note that the HLA Standard Library includes an "os.system" function that does exactly this. Though you still have to specify "cmd /c dir" for such commands, it does encapsulate the process of exec'ing a command line in a somewhat portable fashion (i.e., "os.system" works under both Linux and Windows, though whether or not the command you issue is valid under both systems is another question altogether).
Cheers,
Randy Hyde
Posted on 2004-04-07 14:10:41 by rhyde

Now I have a problem trying to execute the cd command. Every other command (del, mkdir, dir, etc) seems to work except for cd.
Yup. That's because the cmd/command invocation is itself a process - and every process has its own "current directory". You will find the same problem with PATH and SET.
Posted on 2004-04-07 22:38:45 by tenkey
Okay, I'll make 'cd' an internal command then.

The way you describe it makes sence, but should it not also be true if I execute that line from the command line?

For example, if I do this from the command line:

f:\projects>command.com /c cd..

I end up in f:\>

I guess this is one of thos weird Windows things.
Posted on 2004-04-07 23:06:16 by Kain

Okay, I'll make 'cd' an internal command then.

The way you describe it makes sence, but should it not also be true if I execute that line from the command line?

For example, if I do this from the command line:

f:\projects>command.com /c cd..

I end up in f:\>

I guess this is one of thos weird Windows things.


after executing the command though, the command shell will terminate
because of the /c switch..ie: it executes the command and exits..

and a cd..from f:\projects would result in you going back to f:\
thats perfectly normal

perhaps an easier method would be to make a .bat file
runtime with the commands you want in it and executing that?
Posted on 2004-04-08 00:34:24 by evlncrn8



after executing the command though, the command shell will terminate
because of the /c switch..ie: it executes the command and exits..

and a cd..from f:\projects would result in you going back to f:\
thats perfectly normal

perhaps an easier method would be to make a .bat file
runtime with the commands you want in it and executing that?


That's an idea, though it would probably require more work to set that up at this point than to just code an internal CD processing on top of what I already have: It would require creating a temporary batchfile, writing a list of commands to it from the make-script, running the batch then deleting the temporary batch file.
Posted on 2004-04-08 01:19:05 by Kain
It's probably a good idea to catch certain commands internally, anyway, for performance reasons. Things like chdir, delete, rename, ...
Posted on 2004-04-08 06:22:34 by f0dder