Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7700213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:39:23+00:00 2026-05-31T22:39:23+00:00

I want to know how to programmatically execute commands (like dir C:\ or shutdown

  • 0

I want to know how to programmatically execute commands (like “dir C:\” or “shutdown -r”, etc.) in Windows’ Command Prompt (CMD) and retrieve the resulted output, without displaying the black CMD window of course.

I suspect ->this link<- contains the list of required APIs, but I’m not sure which ones to pick, so need your assistance.

Basically this is what I need it for: I want to write simple client-server application (WinSock) where user can sit on the client end and execute commands in (and read replies from) the command prompt of server. Yes – just like Telnet works, but without Telnet, just Win32 API.

Suppose user wants to execute “dir” command on server. He types “dir” on client application, which sends request to the server application, where the command will be executed (as if it was physically typed in command prompt of server) and the output text will be sent back to the client application.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T22:39:25+00:00Added an answer on May 31, 2026 at 10:39 pm

    Although this answer is not a good one for portable software, it works exactly the way you need it if you are sure everything is ok:

    int system(const char *command);
    

    This function executes command in shell (CMD in windows) if available.

    By “if everything is ok” I mean you have a shell in your OS and it is available to you. Generally, this should be true for windows.

    If you call it with NULL, it will give non-zero if shell is available. If you give an actual command, it either returns -1 indicating an error (for example couldn’t spawn a process), or return status of the command which should be OS dependent. Perhaps what you would be most concerned with is “if the command failed” and you should be good by checking the return value against 0 (0 being good).

    Note that to get the output of the command, and you need to save the output somewhere. For example execute the dir command like this:

    error = system("dir > temp.txt 2>&1");
    

    and then retrieve its output from temp.txt.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to know if it is possible to run a command programmatically using
When I insert a DVD or CD, I want to programmatically know what type
want to know why String behaves like value type while using ==. String s1
I want to know programmatically if a view or a layout exists in grails.
I have connected two iPhones via bluetooth programmatically. Now I want to know the
I want to know how to programmatically change the value of <input type=file> I
I am new to Windows Phone 7 Development. I want to know, can I
I want to know if there is any good way of programmatically producing C#
I want to hide the guts of my URL programmatically. I know I can
I want to be able to programmatically read an XSD, prompt a user to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.