batch - echo in multiple colors - batch-file

I'm new to using batch but I know basic commands. I'm trying to show one message (via echo or something like that) in one color. And another message in another color. (the color command colors all the text in the window instead of letting me choose what to color)
I want to do this without external software (although I am using DOSBox instead of cmd - if it matters at all), please explain your code so I can understand and learn.
Thanks.

http://www.dostips.com/forum/viewtopic.php?f=3&t=4453
Here's a ready for use color function

Related

Is it possible to reset the console output color just using SetConsoleTextAttribute() on windows?

I'm looking for a way to use SetConsoleTextAttribute() to reset the output color of the windows console, doing what \033[0m does on Mac and Linux. Is there any way of doing this? I'm looking to avoid external libraries and instead just use windows.h
I don't think there is a reset function, you just have to save the attributes when your program starts.
To determine the current color attributes of a screen buffer, call the GetConsoleScreenBufferInfo function.
cmd.exe works the same way:
color 09
cmd /k
color&rem still blue because this instance started blue
exit
color&rem restored now
Also, don't forget to use SetConsoleCtrlHandler to restore the color on Ctrl+C.

Starting sikuli from batch file, command prompt text won't get coloured

I have made a combination of scripts to execute my test.
Now I have a Main script as well, this one executes the others when needed.
I made a batch file to execute my Run.sikuli file.
It looks like this:
start /min C:\Users\<userName>\Documents\Sikuli\runIde.cmd -r C:\Users\<userName>\Documents\Sikuli\Run.sikuli
Now the above part works fine.
The thing is that I would like to display a different colour of text in the command prompt.
So I added above my line: color 0B
color 0B
start /min C:\Users\<userName>\Documents\Sikuli\runIde.cmd -r C:\Users\<userName>\Documents\Sikuli\Run.sikuli
However, my command prompt is still not black with with light blue letters.
The letters are still white.
Can anyone help me with what I am doing wrong here?
By writing start, you are actually starting a separate window (more info here). So when you set your color, it is only applied to your current window. New window will have its default color again.
NOTE: Just to emphasize, this has nothing to do with Sikuli.

save entire cmd screen to image

I just finished writing a program, (download here if you're interested) Basically, it is like an etch-a-sketch. here's a screenshot of version 1:
Version 2 is more like a pixelated painting program. Here's a screenshot: As you can see, v2 supports 16 different colors.
Anyway, I want the users to be able to "save" their creations. I know that I can highlight everything, and copy it into a text file, but this does not get the colors, and there isn't a clean way to do this (that I know of).
Is there a command line tool that I can download to save screen output as an image? Or am I screwed?
By the way, This is just a batch file, compiled with This program. It only works compiled, because the compiler features advanced commands, the kind that allow me to have multiple colors in one window. You can check out the source code here. All lines starting with REM are the "advanced commands".
:edit
I was originally just going to go with a method that saves all of the text, but when I add colors, it looks something like this. Here is what it should look like:
You can use this commandline tool (I made it in AutoIt):
Capture.exe
Use :
capture.exe outputFile.jpg (png,bmp)
It will capture the entire screen.
EDIT :
You can use THIS new one :
Use :
Capture.exe "Title_of_the_Windows"
So in your bat, give a title to your CMD windows, using :
Title capture
and then display your colored text, and just make a :
Capture.exe "Capture"
This will create Output.jpg.
you can do this without external tools ,but you'll need .net framework (installed on windows from vista and above by default) and screenCapture.bat
call screenCapture screen.png png n

How do I pass values to an non-command line executable with a batch file?

I have an executable that accepts typed user input on three seperate lines on the GUI. The executable also has a button called "create file" that will perform a file creation based on the typed data. My question is how can I automate passing the three typed values into the executable and then execute the "create file" button all from a batch file? I do not have access to the source code so I cannot make modifications there to achieve this.
(Im not able to write comments yet, so I have to use an "answer")
I agree Cebence, as far as I know you need some kind of macro player. Best free I know of is autohotkey (just google for it). It needs a bit reading in at first but is pretty easy to use and very versatile.
Well, this is not really a batch file solution - I don't think one exists. But you could use a tool like Spy++ to find the IDs of the relevant dialog controls and then write a program to:
Launch the executable
Retrieve the main window handle
Send the appropriate window messages
There is probably software out there that can do this. Maybe there's something that you can batch which will just take the process name or ID and pass a single message to it.
If the GUI application doesn't support command-line arguments BAT file will not be of much help here.
What you actually need is some kind of "GUI macro player" application that will execute a script, i.e. macro like this one:
Switch focus to running application named "XYZ"
Find the input box named "text1" and type in "${param1}"
Find the input box named "text2" and type in "${param2}"
Find the input box named "text3" and type in "${param3}"
Find the button named "button" and click it.
I don't know if there are (free) applications that can do this now, but there was a free application called "Act!" or something like it (its icon was a yellow Mickey Mouse glove with a finger pushing a button). It was actually a ZIP file containing a running Windows executable and Delphi application source code, but I can't find it now on PC Magazine's website.
Hope this helps.

Can I easily change the colour of text output to the Windows Console from a C Program

I want to make some printf's to the windows console from my C program but want to make some of them different colours.
Anyone know if this can be done easily?
EDIT: Windows XP is my OS
SetConsoleTextAttribute() will let you set the color of subsequent text output.
http://msdn.microsoft.com/en-us/library/ms686047.aspx
You'll probably want to look at the complete set of Win32 console APIs to be able to get/set/restore and otherwise manipulate the console.
http://msdn.microsoft.com/en-us/library/ms682073.aspx
That's not possible in CMD (correct me if I'm wrong). You can only change the foreground and background color of CMD as a whole. Not by line, or word.
For changing its foreground and background colors please refer to the color command:
color /?

Resources