Running winbatch exe in CMD and getting output there

Started by erezpaz, August 08, 2020, 01:30:23 AM

Previous topic - Next topic

erezpaz

Hi

I want to build a simple exe that will be run in CMD and the output will be text to the same CMD windows. Same output i get by running ping or ipconfig or any other cmd commands.
Can you help with that?

Thanks


ChuckC

It also appears that the newer releases of WinBatch support a native console mode, too.

erezpaz


Stanl, from what i read in the links you sent, you cannot get native output from running an exe. It more like a workaround. I want to pipe output, like this: "mayprogram.exe > test.log". then to be able to see the log output. Same i do with "ping server>test.log".
ChuckC, what is the native command in the recent release?

Thanks

jmburton2001

I've been successful running native Windows executables and piping the output to a text file (like "ping server>test.log") using the comspec environmental variable and then running the executable, with parameters, through ShellExecute.

You won't be able to run this particular example, but it works in the context of the complete script and outputs to the text file created by strOut.

TIP: The one thing I learned the hard way was that punctuation is everything AND (most importantly) the parameters as used on a command line won't necessarily work as the ShellExecute parameters. You need to debug the data that ShellExecute receives from the script.

Code (winbatch) Select

HomeLoc = DirScript()
strCmd = Environment('comspec')
strOut = "%HomeLoc%Checker.txt"
ShellExecute (strCmd, '/c psloglist "Windows" -n 1 -o System -s -t /t >"%strOut%"', HomeLoc, 0, '')


Here's a thread discussing the difficulties of using ShellExecute where the command line parameters need to be modified from the command line version. https://forum.winbatch.com/index.php?topic=2047.msg10515#msg10515

td

Quote from: erezpaz on August 08, 2020, 06:50:34 AM

Stanl, from what i read in the links you sent, you cannot get native output from running an exe. It more like a workaround. I want to pipe output, like this: "mayprogram.exe > test.log". then to be able to see the log output. Same i do with "ping server>test.log".
ChuckC, what is the native command in the recent release?

Thanks

Your description of what you are trying to do is unclear. It can be interpreted as compiling a WinBatch script whose output is directed to stdout and therefore being dumped to a file via one of the command shell's output redirection operators. It could also be interpreted as just needing to launch a command shell application from a WinBatch script and having the output of that command shell application redirected to a file. 

Assuming you mean the former then Stan's links are your best bet.  You may consider it a "workaround" but WinBatch is a GUI application and as a result, the compiler produces GUI applications.  The simple fact is that the Windows environment does not allow GUI applications to have direct access to any console's stdout and stderr.  Those two handle names represent the output targets of a console (command shell). 

WinBatch does have WinBatch Console which is a console mode version of the WinBatch executable but currently, the compiler cannot generate console executables. You will have to use a "workaround" until such time as MSFT changes Windows in some dramatic fashion or the WinBatch Compiler gets the ability to generate console executables. The latter is much more likely than the former but neither is likely in the immediate future.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade