Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 09, 2016, 09:32:21 AM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

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

kris2lee

  • Participant
  • Joined in 2006
  • *
  • default avatar
  • Posts: 1
    • View Profile
    • Donate to Member
IDEA: Run bat files transparently
« on: February 15, 2006, 03:21:09 PM »
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.

jgpaiva

  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • View Profile
    • Donate to Member
Re: IDEA: Run bat files transparently
« Reply #1 on: February 15, 2006, 05:34:11 PM »
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:
Run,THENAMEOFYOURBAT.bat > FILETOSAVETHELOG.log,,Hide,
return
This code will solve your problem, and will only display an icon on the bar for less then half a second, hardly noticeable, and no window.  :Thmbsup:
« Last Edit: February 15, 2006, 05:36:22 PM by jgpaiva »

Gerome

  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 154
    • View Profile
    • Get my Freestyle Basic Script Language + compiler!
    • Donate to Member
Re: IDEA: Run bat files transparently
« Reply #2 on: February 15, 2006, 05:55:41 PM »
Hi,

In Fbsl you just have to do that :
StrPipe( "CMD.exe /K test.bat", SW_HIDE )

Into the bat file you can do such code :
@echo off
Echo Hello World! > log.txt

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 ;)
Yours,
(¯`·._.·[Gerome GUILLEMIN]·._.·´¯)
http://www.fbsl.net [FBSL Author]
http://gedd123.free.fr/FBSLv3.zip [FBSL Help file]
(¯`·._.·[If you need help... just ask]·._.·´¯)
« Last Edit: February 15, 2006, 05:58:56 PM by Gerome »

Rover

  • Master of Smilies
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 630
    • View Profile
    • Donate to Member
Re: IDEA: Run bat files transparently
« Reply #3 on: February 15, 2006, 08:09:27 PM »
I was ready to give you the quick intro to the detach command.  Then I remembered, it's an OS/2 thing.

You can run a cmd.exe window minimized with no output, but that's not quite the same.

Once again, if OS/2 ruled the world, things would be better  ..  ;)
Insert Brilliant Sig line here

Rover

  • Master of Smilies
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 630
    • View Profile
    • Donate to Member
Re: IDEA: Run bat files transparently
« Reply #4 on: February 15, 2006, 10:34:16 PM »
Aha!  How about this?

at 23:28 "%systemroot%\system32\cmd.exe /c k:\status\test.bat"

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.



Detach under OS/2 would have been easier   ;D
Insert Brilliant Sig line here

AbteriX

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 1,115
    • View Profile
    • Donate to Member
Re: IDEA: Run bat files transparently
« Reply #5 on: February 16, 2006, 02:04:39 AM »
How about this with VB for WSH

ExecuteHidden.vbs
- - - - - - -8< - - - - - - - - - - - - - - - - - - - 8<- - - - - - - - - - -
Set WshShell = WScript.CreateObject( "WScript.Shell" )
WshShell.Run
"c:\test.cmd" ,0,True
- - - - - - - 8<- - - - - - - - - - - - - - - - - - - 8<- - - - - - - - - - -

wr975

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 369
    • View Profile
    • Donate to Member
Re: IDEA: Run bat files transparently
« Reply #6 on: February 16, 2006, 04:56:15 AM »


You can use "consoletool.exe" to hide a console window, if you don't want to use AutoHotkey.

consoletool.exe /HIDE


Quote
For example mybackup.2005-02-15.1.log.


This one creates a unique name (date and time) using built in commands:

for /f "Tokens=1-4 Delims=/ " %%i in ('date /t') do set dt=%%i-%%j-%%k-%%l
for /f "Tokens=1" %%i in ('time /t') do set tm=-%%i
set tm=%tm::=-%
set dtt=%dt%%tm%
@echo createdname : %dtt%


Or use the external tool "now.exe":

for /F %%i in ('now.exe yyyy.mm.dd---ddd---hh-nn') do set dtt=%%i
@echo createdname : %dtt%


I've attached consoletool.exe and now.exe to this answer.

bliss

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 19
  • la la la-la
    • View Profile
    • bLisTeRinG soft
    • Read more about this member.
    • Donate to Member
Re: IDEA: Run bat files transparently
« Reply #7 on: April 28, 2006, 08:39:14 AM »
Another answer is to put your command line into a normal shortcut (.lnk) and set the properties to  run minimized, and to close when finished. You can also choose an icon this way.
Am we there yet?

rjbull

  • Charter Member
  • Joined in 2005
  • ***
  • default avatar
  • Posts: 2,927
    • View Profile
    • Donate to Member
Re: IDEA: Run bat files transparently
« Reply #8 on: April 28, 2006, 09:05:33 AM »
put your command line into a normal shortcut (.lnk) and set the properties to  run minimized, and to close when finished.

You may need to put CLS and EXIT and the end of the batch file for this to work, under some versions of Windows.

I sometimes put logging into the batch file itself, using:


------------------------------------------------------------------------
LOGECHO   Echo with date/time           Ver 2.2 (c) 2001 Horst Schaeffer
------------------------------------------------------------------------

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

Tokens (see also: LOGECHO /?):

        upper case tokens:              lower case tokens:

        $D  day                             $h  hour
        $M  month (01..12)              $m  minutes
        $N  month (Jan..Dec)            $s  seconds
        $H  month (hex 1..C)            $c  sec/100
        $Y  year (00..99)
        $C  century (19|20)
        $W  day of week (Sun..Sat)
        $V  day of week (0..6)
        $Z  day of year (001..366)

        $$  Dollar symbol
        $+  new line


Example for a logfile (to append use double redirection symbols!):

        LOGECHO ----------  $W $D $N $Y, FDNC>> FD.LOG
        LOGECHO # $h:$m:$s  GUS %NL% node\>> FD.LOG


Horst's Web site is http://home.mnet-online.de/horst.muc/  LOGECHO is included in his PBATS collection.


Rover

  • Master of Smilies
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 630
    • View Profile
    • Donate to Member
Re: IDEA: Run bat files transparently
« Reply #9 on: April 28, 2006, 09:10:17 AM »
You can also use nnCron Lite to schedule commands. I've been running it for a couple of years w/ NO problems.
http://www.nncron.ru/
Insert Brilliant Sig line here

Hirudin

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 543
    • View Profile
    • Donate to Member
Re: IDEA: Run bat files transparently
« Reply #10 on: April 28, 2006, 06:55:59 PM »
Hi,

In Fbsl you just have to do that :
StrPipe( "CMD.exe /K test.bat", SW_HIDE )

Into the bat file you can do such code :
@echo off
Echo Hello World! > log.txt

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.

Here's some more info, directly from Microsoft.