Running from .bat file without GUI

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

Running from .bat file without GUI

Post by colin123 »

Hi

Can anyone give me an example of a command line I could use from a windows .bat file to invoke the 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
Posts: 726
Joined: Mon Dec 13, 2004 1:50 pm
Location: Tannhauser Gate

Re: Running from .bat file without GUI

Post by MikeGale »

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
Posts: 2
Joined: Wed Mar 12, 2014 5:23 pm

Re: Running from .bat file without GUI

Post by colin123 »

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
Posts: 726
Joined: Mon Dec 13, 2004 1:50 pm
Location: Tannhauser Gate

Re: Running from .bat file without GUI

Post by MikeGale »

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
Posts: 3785
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Running from .bat file without GUI

Post by Albert Wiersch »

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/current/do ... d_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/current/do ... 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
Albert Wiersch, CSS HTML Validator Developer • Download CSS HTML Validator FREE Trial
User avatar
Albert Wiersch
Site Admin
Posts: 3785
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Running from .bat file without GUI

Post by Albert Wiersch »

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.
Albert Wiersch, CSS HTML Validator Developer • Download CSS HTML Validator FREE Trial
User avatar
MikeGale
Rank VI - Professional
Posts: 726
Joined: Mon Dec 13, 2004 1:50 pm
Location: Tannhauser Gate

Re: Running from .bat file without GUI

Post by MikeGale »

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
Posts: 3785
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Running from .bat file without GUI

Post by Albert Wiersch »

Thank you Mike. Would you mind if I incorporated some of your script information in CSS HTML Validator's documentation?
Albert Wiersch, CSS HTML Validator Developer • Download CSS HTML Validator FREE Trial
User avatar
MikeGale
Rank VI - Professional
Posts: 726
Joined: Mon Dec 13, 2004 1:50 pm
Location: Tannhauser Gate

Re: Running from .bat file without GUI

Post by MikeGale »

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
Posts: 3785
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Running from .bat file without GUI

Post by Albert Wiersch »

Thanks Mike.

For #2, are you referring to setting $_JOB.startdate and $_JOB.starttime in onFunctionsLoad()?
Albert Wiersch, CSS HTML Validator Developer • Download CSS HTML Validator FREE Trial
User avatar
MikeGale
Rank VI - Professional
Posts: 726
Joined: Mon Dec 13, 2004 1:50 pm
Location: Tannhauser Gate

Re: Running from .bat file without GUI

Post by MikeGale »

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
Posts: 3785
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Running from .bat file without GUI

Post by Albert Wiersch »

Albert Wiersch, CSS HTML Validator Developer • Download CSS HTML Validator FREE Trial
User avatar
MikeGale
Rank VI - Professional
Posts: 726
Joined: Mon Dec 13, 2004 1:50 pm
Location: Tannhauser Gate

Re: Running from .bat file without GUI

Post by MikeGale »

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
Posts: 3785
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Running from .bat file without GUI

Post by Albert Wiersch »

Thanks Mike... I've added that for the next update (it's not on the website yet).
Albert Wiersch, CSS HTML Validator Developer • Download CSS HTML Validator FREE Trial
Post Reply