Doubts executing batch script files on windows

Everything else that doesn't fall into one of the other PB categories.
Nuno
New User
New User
Posts: 3
Joined: Mon Mar 29, 2021 1:55 pm

Doubts executing batch script files on windows

Post by Nuno »

Hello all.

I'm trying to code and create an automated process to execute batch script files using Purebasic.
An example on what I'm trying to do via command line...

xpto.bat --mode ccXXxx project new --name files2place --device XXXXXXX --mode production --overwrite > xpto.log

In the end I want to get also the respose to the command placed and checkout some information...

Any idea on how can I solve this?

Best Regards
Nuno
Marc56us
Addict
Addict
Posts: 1479
Joined: Sat Feb 08, 2014 3:26 pm

Re: Doubts executing batch script files on windows

Post by Marc56us »

Since you are redirecting all output to a file, you will not see anything until the program is finished.
So you have to wait (#PB_Program_Wait) and then display the log file, either by reading it as a text file or by displaying it with the associated program.

Something like this:

Code: Select all

Run = RunProgram("cmd", 
                 "/c xpto.bat --mode ccXXxx project new --name files2place --device XXXXXXX --mode production --overwrite > xpto.log",
                 #PB_Program_Hide, #PB_Program_Wait)

If Run 
    RunProgram("xpto.log")
    ; RunProgram("notepad", "xpto.log", "")
EndIf
Without the redirection, it is possible to see the result line by line as in the example given in the help on RunProgram()

PS. If one of your parameter need double quote, uses C convention formatting, like this:

Code: Select all

For:
"C:\Program Files"

Uses:
~" \"C:\\Program Files\" ... "
:wink:
Post Reply