Jump to content
  • Advertisement
Sign in to follow this  

Run console command in Windows without console...

This topic is 4830 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there a way to run a system command in a windows program without having a console window popup to run it? I need to run a batch file but don't want a console window to popup... Thanks in advance [grin]

Share this post


Link to post
Share on other sites
Advertisement
Sure, just execute the console application from a console-less application.

There's probably an easy way to do it without writing custom applications too (rundll perhaps?), but I didn't bother googling last time I needed to do this.
You could probably pipe the output onto some other application too. But the MSVC debugger would only let me spawn raw executables (no batch files or input redirection) and I wanted a way to launch emulated executables.
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

int WINAPI WinMain(HINSTANCE instance, HINSTANCE prev, LPSTR cmdline, int cmdshow)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;

ZeroMemory(&si, sizeof(si));
ZeroMemory(&pi, sizeof(pi));
si.cb = sizeof(si);

if(!CreateProcess(NULL, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) {
return 1;
}

WaitForSingleObject(pi.hProcess, INFINITE);

CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return 0;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!