Donotalo
Donotalo

Reputation: 13025

Executing command prompt's functionality using Win32

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.

Upvotes: 1

Views: 2732

Answers (5)

user82238
user82238

Reputation:

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.

Upvotes: 0

Ismael
Ismael

Reputation: 3013

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.

Upvotes: 0

anon
anon

Reputation:

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.

Upvotes: 0

Joey
Joey

Reputation: 354426

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.

Upvotes: 5

user83286
user83286

Reputation:

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.

Upvotes: 1

Related Questions