Hide Command Prompt Window when RUN Batch file

And I thougth ChatGPT was fast :slight_smile:

@Mark_Sarson thanks for the fast answer and example. Let me test this, if I encounter some additional problems I’ll get back here.

Hello everybody,

Sorry it took me long to reply, but this sample was perfect and did the job very well.

Best Regards

Hi Mark, two additional question on your example, where do I exactly add this part of code in the Global embeds:

. It’s the prototype of ExtendedRun.
And the Group vars:
image
Many thanks

Hi @sk2107

It’s not the example, i’m sure it works, it’s more a problem on my end on implementing it.

Hi Edi,

I presume you are doing this in an APP Gen application, If so, then the first part will get generated for you if you coded an app gen source procedure called ExtendedRun then that will automatically be in place. I would suggest doing this for the procedure if in app gen.

The type definition, again if in app gen, will go after Global Includes in the global embed point.

Mark

Hi Mark,

Exactly. I’ve placed the code in the right embeds in Global and now everything works fine. Thanks for the help and example it helped a lot.

Hi @Mark_Sarson
I’m still having problems when running the ExtendedRun procedure in my app. Apperantly it won’t send any parameters i add.
What I try to achieve is the following:

  1. Run an .exe file through cmd.exe and pass it 2 parameters.

  2. The 2 parameters hold paths to a .txt file and the other to a .bmp file, and when combined those are used to create a barcode on a document.

  3. the code i used for sending those parameters to the ExtendedRun is the following:

  • ExtendedRun(‘cmd.exe’, '/C ’ + mypath, ‘’, 0, 0, 0)

  • ExtendedRun (‘cmd.exe’ , ’ ’ , mypath, 0, 0,0)

  • ExtendedRun (‘my.exe’ , 'added here the params to pass ’ , ’ ', 0, 0, 0)

None of above work. Also what I noticed is that the cmd.exe is opened normally, but nothing else happens because the parameters are not passed. Any clue what could be the issue?

Use & for concatenation in cw
Not +

Provide a sample of what myPath actually is.
Sounds like you’ll need to call a batchfile to do some processing rather than just a .txt or .bmp file

Hi @MarkGoldberg
Yes I use the & for concat, this was a typo.

mypath is a string(200) variable which stores the path of the 3 files:
CLIP(SYS)&‘BARKOD.EXE’ C:\myapp\BARKOD.TXT C:\myapp\BARKOD1.BMP
I.e I create add the value to it in the following way
mypath=CLIP(SYS)&‘BARKOD.EXE’ CLIP(SYS)&‘BARKOD.TXT ‘&CLIP(SYS)&‘BARKOD’&I&’.BMP’

Till now I’ve been using the following run(mypath,1), and it runs in cmd without problem. It passes the whole string as it is and cmd does the rest. Using the ExtendedRun it somehow doesn’t get the params I’d like to pass.

I’ve just noticed a slight bug in my code. So I am sorry for that.

Change the line
IF NOT OMITTED(szParams) THEN

To
IF NOT OMITTED(inParams) THEN

I have updated the gist.

Mark

You don’t show what SYS is so check … does it end with a backslash ?

Just pass the BARKOD.EXE as the first parameter …

Run(CLIP(SYS) & 'BARKOD.EXE’, CLIP(SYS) & 'BARKOD.TXT ' & CLIP(SYS) & 'BARKOD.BMP', etc )

I see you have some arbitrary length limitations in your gist

The overall length appears to be limited to just under 8K (8191)
Command prompt line string limitation - Windows Client | Microsoft Learn

1 Like

a string(200) could easily be too small for 3 paths
I would use 3 * FILE:MaxFilePath + 2
which is to say 3 * 260 + 2 = 782
the + 2 is for the space between each arguments 1 & 2 and between 2 & 3

that doesn’t look quite right. Maybe this:

mypath=CLIP(SYS)&‘BARKOD.EXE ’&CLIP(SYS)&‘BARKOD.TXT ‘&CLIP(SYS)&‘BARKOD’&I&’.BMP’

Julian asked if SYS ended with a backslash… using StringTheory

st.setValue(SYS,st:clip)
if not st.EndsWith('\') then st.append('\').
st.setValue(st.getValue() & ‘BARKOD.EXE ’ & st.getValue() & ‘BARKOD.TXT ‘ & st.getValue() & ‘BARKOD’&I&’.BMP’)
! note in above line we did not need to clip(SYS) three times
run(st.getValue(),1)

you could have simply said:

st.setValue(SYS,st:clip)
if not st.EndsWith('\') then st.append('\').
run(st.getValue() & ‘BARKOD.EXE ’ & st.getValue() & ‘BARKOD.TXT ‘ & st.getValue() & ‘BARKOD’&I&’.BMP’,1)

but I often find it is handy to have the value in an ST object in case you want to log or trace:

st.trace()

or perhaps

st.trace('about to run: ’ & st.getValue())

Mark G pointed out that 200 chars might be too small - using ST you avoid arbitary size limits (well apart from the hard limit on the amount of memory.)

You seem to be showing the first parameter to my version of RUN() as combined program name and command line, that is not correct unless you have changed my sample code,

ie: The first parameter should be the application name (including the full path if necessary), the second parameter is the command line, third parameter onwards are the options.

That was my fault, as I wrote about 3 parameters when there were only two.

In either case, the general premises still apply

I’ve updated the gist to implement dynamic sizing of the filename, path and parameters sizes and fixing another bug that was pointed out to me.

Hi @Mark_Sarson , that was the bug that acctually prevented cmd getting the needed parameters. On the old code the paramteres were newer passed through, and it could never execute the other commands.

After a bit code changing everything now works fine, I’ve implemented succesfully the ExtendedRun.

Also thanks to others for joining the discussion and help.

Case closed(for now :sweat_smile:)