tags:

views:

423

answers:

5

What Windows API functions are available to execute command prompt's functionality? For example, I like to execute dir command and want to show the output in GUI without using cmd.exe in Windows.

+1  A: 

The dir command is built into the cmd.exe, it's not a separate executable. There's no way of executing it short of running cmd.exe.

EDIT: As for the displaying of results, you need to fill in the STARTUPINFO.hStdXXX members, probably using an anonymous pipe. See this example.

jachymko
+3  A: 

You can start cmd /c dir S:\ome\Path from your process and grab the output. Otherwise it's not possible. But if you're not interested in particular formatting details of dir then you're probably better off just enumerating files/directories and display them.

Joey
That should be cmd /k dir, otherwise cmd will not exit after completing the dir command.
Ferruccio
exactly vice-versa. /k remains, /c doesn't. Just take a look at cmd /?
Joey
You're right. My mistake.
Ferruccio
A: 

For a console app you can use popen(), but things are by no means so easy from a GUI app. See http://msdn.microsoft.com/en-us/library/ms682499%28VS.85%29.aspx for one approach.

anon
A: 

If you want a listing of files in a given folder see this question which describes how to achieve it, using windows api or a more generic boost approach.

Ismael
A: 

Everything the Windows command line does is done through the Win32 APIs.

For example, with regard to "dir", FindFirstFile() and FindNextFile() will give you the contents of a directory.

For any given command, you will need to figure out which APIs/function calls are in use and then learn how to use them yourself in your own code.

Blank Xavier