Running from .bat file without GUI

For technical support for all editions of CSS HTML Validator. Includes bug reports.
Post Reply
colin123
Rank 0 - Newcomer
Rank 0 - Newcomer
Posts: 2
Joined: Wed Mar 12, 2014 5:23 pm

Running from .bat file without GUI

Post by colin123 » Wed Mar 12, 2014 5:30 pm

Hi

Can anyone give me an example of a command line I could use from a windows .bat file to invoke CSE validator as part of a larger build process, to run both validation and link checking on one or more HTML files that are created by my build process, and have the validator save its results to text files, but without any validator GUI appearing?

Basically I dont want any GUI showing at all, so it can be run as part of an existing (and lengthy - several hours) build process without getting in the way of my interactive use of the machine.

Then I can review the results later at my leisure.

Thanks

User avatar
MikeGale
Rank VI - Professional
Rank VI - Professional
Posts: 708
Joined: Mon Dec 13, 2004 1:50 pm
Location: Tannhauser Gate

Re: Running from .bat file without GUI

Post by MikeGale » Thu Mar 13, 2014 12:43 am

Other than driving the engine from your own code, (Which can be done but takes a fair amount of work) it is probably not too hard to write a little command line process of your own. (If I were doing that I'd write something using .NET. Process.Start and ProcessStartInfo may be useful. Not a big programming job.)

The code might fire up the batch wizard in a non-visible way, take parameters that define and start a batch process and run it asynch. (The choice for using asynch depends on the nature of your build.) Would need some testing to make sure there's no obstacles, when using suitably configured batch runs. (If you're doing that the TNPL has some remarkably powerful capabilities that could be used to give you custom reporting.)

You could also put in a request for a "-silent" option in a coming edition.

colin123
Rank 0 - Newcomer
Rank 0 - Newcomer
Posts: 2
Joined: Wed Mar 12, 2014 5:23 pm

Re: Running from .bat file without GUI

Post by colin123 » Thu Mar 13, 2014 2:51 am

An out of the box '-silent' mode of operation would be ideal. Ie an easy way to run it once off from command line to validate given file(s) with given option(s) (also given on command line), have all errors etc written to stdout/stderr which can then be captured in a text file using command line output redirection ('>').

User avatar
MikeGale
Rank VI - Professional
Rank VI - Professional
Posts: 708
Joined: Mon Dec 13, 2004 1:50 pm
Location: Tannhauser Gate

Re: Running from .bat file without GUI

Post by MikeGale » Thu Mar 13, 2014 4:48 am

If it fits your situation, I recommend trying PowerShell instead of .bat.

You can often put .bat lines into a PowerShell script, they just work. When you need to do more sophisticated things you have a better programming environment.

(For example, I imagine you can code the utility I describe above in PowerShell, without difficulty.)

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3412
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Running from .bat file without GUI

Post by Albert Wiersch » Thu Mar 13, 2014 10:14 am

The first thing I would try - and one of the easiest - is to create a Batch Wizard target list that can be run from the command line processor using a "-b" command (like -b1 to validate) followed by the target list to process. More information is here:
http://www.htmlvalidator.com/v140/docs/command_line.htm

An example would be:

Code: Select all

cmdlineprocessor.exe -b1 <target list to process>
That will, by default, cause the Batch Wizard GUI to appear, but you should be able to minimize it and get it out of the way while you do other things. If you have a multi-core CPU, then I doubt there would be any issues with system responsiveness while the Batch Wizard does its work in the background.

The Batch Wizard will generate an HTML report, and you can specify where the report will be generated when you build and save the target list, otherwise it will use the default in the Batch Wizard Options. Using the Batch Wizard will allow link checking, and you should see link reports in the report that will be generated (as long as you have enabled link checking in the Batch Wizard Options). And of course you could look at the report whenever you want, though it will be deleted & overwritten if you run the Batch Wizard again with a job that uses the same report filename.

You may want to generate your own target list on the fly if the files you want to validate will be changing. You could then pass this file to the Batch Wizard to process. Here is more information on how to construct a target list for the Batch Wizard:
http://www.htmlvalidator.com/v140/docs/ ... ormats.htm

The above shows the older formats that the Batch Wizard still understands. These are easier to construct, especially the one that only requires "URL :", "File:", or "Dir :" before each line.

If you find that this works but you want some sort of option to start the Batch Wizard minimized, then let me know and I can see if I can add it in a future update. The GUI will still be there, but it should start minimized and out of your way.

You may also want to send a "-q" signal which will cause the Batch Wizard to exit when it's finished:

Code: Select all

cmdlineprocessor.exe -q
Image
Albert Wiersch

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3412
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Running from .bat file without GUI

Post by Albert Wiersch » Thu Mar 20, 2014 5:00 pm

In the next update, I've added a "-minimize" option that should launch the editor and Batch Wizard minimized. The editor GUI may briefly appear but it should be quickly and automatically minimized if this new option is used, so it should stay out of the way.
Image
Albert Wiersch

User avatar
MikeGale
Rank VI - Professional
Rank VI - Professional
Posts: 708
Joined: Mon Dec 13, 2004 1:50 pm
Location: Tannhauser Gate

Re: Running from .bat file without GUI

Post by MikeGale » Sun Mar 30, 2014 6:37 pm

I've used the updated version. It can be used to run, and exit, the GUI mostly invisibly.

In my testing the GUI gives a brief appearance before minimising.

I ran it using a trivial PowerShell script, though much the same can be done with a batch file.

Code: Select all

start-process <filepath>\cmdlineprocessor.exe -ArgumentList "-b <filepath>\<projectName>.lst -minimize" -RedirectStandardOutput "<filepath>\<projectName>-StdOut.csv" -RedirectStandardError "<filepath>\<projectName>-StdErr.txt"

start-process <filepath>\cmdlineprocessor.exe -ArgumentList "-q" 
(Quick Summary: That's a ps1 script file on Win 8.1, and I redirect some output, which might prove useful should something ever go wrong. (In normal operation the redirection is invisible and irrelevant.) The code can obviously do whatever else you need, like compare to previous validation.)

My batch process, outputs XML (which is nicely machine readable) and also lists all errors etc. in a CSV format datatable. That latter could be used from database code to automate analysis. (I uses some user defined functions to create the database and in a few other ways.)

With the above, and a custom configuration (if you need it) some powerful automated testing is possible today.

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3412
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Running from .bat file without GUI

Post by Albert Wiersch » Mon Mar 31, 2014 9:04 am

Thank you Mike. Would you mind if I incorporated some of your script information in CSE HTML Validator's documentation?
Image
Albert Wiersch

User avatar
MikeGale
Rank VI - Professional
Rank VI - Professional
Posts: 708
Joined: Mon Dec 13, 2004 1:50 pm
Location: Tannhauser Gate

Re: Running from .bat file without GUI

Post by MikeGale » Mon Mar 31, 2014 8:26 pm

No problem for you to use that.

Two additional things (to those mentioned above) worth mentioning would be.
  1. Turn off random advice items, in the configuration
  2. Set date and time to a standard value in a user defined function to improve a comparison

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3412
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Running from .bat file without GUI

Post by Albert Wiersch » Tue Apr 01, 2014 8:46 am

Thanks Mike.

For #2, are you referring to setting $_JOB.startdate and $_JOB.starttime in onFunctionsLoad()?
Image
Albert Wiersch

User avatar
MikeGale
Rank VI - Professional
Rank VI - Professional
Posts: 708
Joined: Mon Dec 13, 2004 1:50 pm
Location: Tannhauser Gate

Re: Running from .bat file without GUI

Post by MikeGale » Tue Apr 01, 2014 6:27 pm

Yep I set startdate and time so that they show up the same for diff tools.

I also save reports, one per web-page, renamed (based on the page URL). This means that they, just work, with diff tools. (A page is always reported under the same filename.)

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3412
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Running from .bat file without GUI

Post by Albert Wiersch » Wed Apr 02, 2014 11:50 am

Image
Albert Wiersch

User avatar
MikeGale
Rank VI - Professional
Rank VI - Professional
Posts: 708
Joined: Mon Dec 13, 2004 1:50 pm
Location: Tannhauser Gate

Re: Running from .bat file without GUI

Post by MikeGale » Wed Apr 02, 2014 6:44 pm

I think that's great. Succinct yet it says what's needed.

The only other thought is to add a bit to the quit line

Code: Select all

... -RedirectStandardError "<filepath>\<projectName>_Quit-StdErr.txt"
would round it off with a way to identify any malfunctions in closing the UI. (I haven't executed that yet!)

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3412
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Running from .bat file without GUI

Post by Albert Wiersch » Thu Apr 03, 2014 9:49 am

Thanks Mike... I've added that for the next update (it's not on the website yet).
Image
Albert Wiersch

Post Reply