Run .bat file - Forum

Forum Navigation
You need to log in to create posts and topics.

Run .bat file

Hi guys,

I want to run a .bat file to search for jpeg (.jpg) files, list it and then read it back into ListBox within my app.

What i got is... In my "Embedded Files" i got a .bat file named "JPeg.bat

JPeg.bat contains this script

dir /s /b *.jpg | findstr /v .jpg. >jpg.txt

<If i normally run the .bat file in (Lets say) My Documents/My Pictures/

It will search for all the .jpg files in "My Pictures" Folder and list it in jpg.txt

This works, but i want to run the .bat file within my app>

What i try was

When button clicked

First it extract the file

ExtractFile "[Embedded]JPeg.bat" "!C:\Users\MyPC\Pictures\Jpeg.bat"

Then it must run the .bat file and list it in jpg.txt file

Run "!C:\Users\MyPC\Pictures\JPeg.bat" "" "RunOnce+Wait+LoadComplete" "" ""

Then it must read the jpg.txt file into ListBox

FileRead "C:\Users\MyPC\Pictures\jpg.txt" "All" "[ListBox2]"

It seems to run but it don't list or create the jpg.txt file

Any help please

@impactband4u

dir /s /b *.jpg | findstr /v .jpg. >jpg.txt

This command will look for .jpg files in all subfolders of the CURRENT folder

normally run the .bat file in (Lets say) My Documents/My Pictures/

So it will report all .jpg files in subfolders of My Documents/My Pictures/

ExtractFile "[Embedded]JPeg.bat" "!C:\Users\MyPC\Pictures\Jpeg.bat"

But if you extract the embedded file to C:\Users\MyPC\Pictures, is that the same as My Documents/My Pictures/ ?

check in the expected folder if the .bat file was extracted ?

It seems to run but it don't list or create the jpg.txt file

How did you determine that it ran ?

Using File Explorer, do a global search for jpg.txt ... the bat file might have created this file at a location (folder) you did not expect.

Also, you have specified both "Wait" and "LoadComplete" ... there might be an outside chance that it only waits until "LoadComplete" and not until the bat file is done ... try it with just "Wait".

With the Run command, you can specify a subroutine to be executed upon completion ... try and check for this file inside such a subroutine.

@impactband4u

Also take a look at the help file info about Predefined Global Variable [CurrentDir]

Contains the current active folder. Use in conjunction with the Run Action to specify an application's working directory. This will become the active directory when the application is launched. For example:

SetVar "[CurrentDir]" "c:\windows"
Run "C:\MyPrograms\MyApp.exe" "" "Normal"

To disable the Run action's use of the working directory, simply set [CurrentDir] to null. For example:

SetVar "[CurrentDir]" ""

Another reason the search folder and the resulting txt file location might NOT be as expected.

check in the expected folder if the .bat file was extracted ?

Yes, the .bat file extracted into the the expected folder

How did you determine that it ran ?

I can see the command prompt window (black window) shows up quickly when i try to run the .bat file, so i assume it did run but not completely sure.

Using File Explorer, do a global search for jpg.txt ... the bat file might have created this file at a location (folder) you did not expect.

I did but no, it didn't save the jpg.txt anywhere

Also, you have specified both "Wait" and "LoadComplete" ... there might be an outside chance that it only waits until "LoadComplete" and not until the bat file is done ... try it with just "Wait".

I tried all of the option on and off but still nothing

With the Run command, you can specify a subroutine to be executed upon completion ... try and check for this file inside such a subroutine.

I will see if i can get something to work in the subroutine

 

Thank You

SetVar "[CurrentDir]" "c:\windows"

I used

SetVar "[CurrentDir]" "!C:\Users\MyPC\Pictures\"
Run "!C:\Users\MyPC\Pictures\JPeg.bat" "" "Normal" "" ""

Thank You, This worked for me :)

 

@impactband4u

This worked for me :)

Yee Haaa !!!

May I suggest that you still use the "RunOnce+Wait" option in the Run command ... otherwise, VisualNEOWin could service your next command (FileRead) BEFORE the bat file has had a chance to scan through all the subfolders.

Yes i use the

Do not run more than one copy.......

Wait for application to close.........

Wait for application to finish..........

Run application hidden

 

Everything work fine :)