Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Hiding or minimizing a dos window

Subject: Hiding or minimizing a dos window

From: Paul Mennen

Date: 6 Feb, 2013 02:27:14

Message: 1 of 2

I'm redirecting the output of a dos program (under Win7x64) to a text file with:

dos('DosProgram parameters > output.txt &');

This works well except for the fact that I want to hide or minimize the dos window.
I've read that this can be done by using some combination of parameters with the start command and/or cmd.exe, but if so it must require some magical combination that I haven't yet discovered. I've tried hundreds of dos(' ') commands but none of them has done the right thing. Sometimes two dos windows are created and only one of them is minimized, and sometimes the redirection doesn't work. So I've pretty much given up hope on that approach unless someone knows exactly how it is done.

I have downloaded a program called WindowAPI which can minimize a window given its HWND handle. I've found that this works for a matlab figure since this same program can be used to find the HWND handle of a matlab figure. It probably would work on a console window as well if I could pass in the HWND handle of the console window, but unfortunately I don't know how to find this handle. Does anyone know how to do this?

Thanks
~Paul

Subject: Hiding or minimizing a dos window

From: Paul Mennen

Date: 7 Feb, 2013 08:54:08

Message: 2 of 2

Ok, with much struggle I've finally answered my own question about how to run a background dos program in a minimized window. So I thought I should share it. My solution is to follow the background dos program call with another dos program that minimizes the first window as follows:

> dos('DosProgram parameters > output.txt &'); % start background task
> dos('WinMin'); % minimize the background task window

WinMin.exe is a program I created myself. If you would like this exe, you can make it by creating a text file with the name WinMin.ahk that contains the following single line:

WinMinimize, C:\Windows\system32\cmd.exe

Then install "autohotkey". Then right click on the ahk file and select "compile".
That's it ... you'll have your very own dos window minimizer. And by the way, the call to WinMin.exe does not create its own dos window because it does not need to run in the background and thus does not include the trailing ampersand character.

I was thinking of putting WinMin.exe on the file exchange, but I would feel a bit silly doing so since I suspect there is a simpler more elegant method routinely used to do this that I just don't know about.

~Paul

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us