Author
Topic: IDEA: Run bat files transparently (Read 7753 times)

I started to thinking why I do not like Windows command line option so much. Well I use it a lot but I could get more from it.

One simple idea would be running some batch using scheduler that will backup my images from one harddrive to another. This would be simple copy command but... but it will open ugly command window that will fill my screen and got the focus.

So to get most out from command line I should be able to run it silently and log the output into file. One file per bat file execution for example. Name can be generated from bat file name adding number (or/and date) and .log extension. For example mybackup.2005-02-15.1.log.

There are two ways of doing this.I could create a script that can run your bat file and hide the console when it runs the bat file. This is the harder way.Or in about 3 minutes, you could learn how to use autohotkey and do it yourself

As i'm a nice guy, here you go:In ahk, the code you're looking is something like this:

The at command schedules commands. See cmd /? for the explaination of /c. Be aware that each command runs in its own environment so you need to fully path the cmd.exe and the command that you want to run. See at /? for details on scheduling the commands.

The test I ran worked without anything showing on my screen. No focus change, etc.

LOGECHO is used like ECHO, and supports the tokens for all sorts of datafrom the current date and time. LOGECHO was especially made to producecustom entries for logfiles, but it can also be used to write commandsinto a temporary BAT file (to rename, set, pkzip etc...)

Your bat will be executed silently and without any console output thanks to thr SW_HIDE parameter

The StrPipe has more extends in Fbsl, you can redirect the piped process to any valuable Handle, that is to say it's very handy to grab a result from something that writes into stdout

Enjoy

I think this is definately the way to go if all you want is a log of what was done. You don't need to program anything, you don't need to use another program, all you have to do is add something like "> log.txt" to the end of the commands in your batch file.

From the little I've used this, it pretty much puts whatever would be "written" in the DOS window into a file instead.