Run a batch file within batch file using VBA

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
wasimsono
Posts: 11
Joined: 03 Apr 2017 06:06

Run a batch file within batch file using VBA

#1 Post by wasimsono » 01 Feb 2018 22:09

Dear all

I have two batch files named as :
1) Combine.bat
2) Picenquiry.bat

The contents of Combine.bat file are as:

Code: Select all

@echo off
for %%A in (*.txt) do (
  echo Processing file '%%A'
   
  FOR /F "delims=" %%L in (%%A) do (
    ECHO %%L%%A >> DataFile.txt
  )
)
and contents of Picenquiry.bat are as:

Code: Select all

@echo off
ren "F:\meter_pictures\??????rc*." *.txt 
rem call "F:\meter_pictures\combine.bat"
I am using a button on form and following code is used for click on button:

Code: Select all

strReportpath = "F:\meter_pictures\"
Shell strReportpath & "Picenquiry.bat"
Unfortunately It runs but only run Picenquiry.bat file and do not run Combine.bat file as it is called in this batch file.

But when I run Picenquiry.bat file directly without using VBA i.e. by double clicking file name, it runs and make "DataFile.txt".

What mistake I am doing? Please help me. Its urgent.

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Run a batch file within batch file using VBA

#2 Post by ShadowThief » 01 Feb 2018 22:41

The line in Picenquiry.bat that calls combine.bat is commented out.

wasimsono
Posts: 11
Joined: 03 Apr 2017 06:06

Re: Run a batch file within batch file using VBA

#3 Post by wasimsono » 02 Feb 2018 01:18

If I remove Comment then also same result found. How can I run second batch file within Picenquiry.bat ?

wasimsono
Posts: 11
Joined: 03 Apr 2017 06:06

Re: Run a batch file within batch file using VBA

#4 Post by wasimsono » 13 Feb 2018 04:25

I removed comment.
I also run only combine.bat file but still no result found.

Anyone can help out.

regards.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Run a batch file within batch file using VBA

#5 Post by penpen » 13 Feb 2018 06:16

The Phrases "If I remove Comment" and "I removed comment." sound like you have misunderstood ShadowThief.
I'm pretty sure he wanted you to end up with this "Picenquiry.bat" (which successfully processed the related "combine.bat"):

Code: Select all

@echo off
ren "F:\meter_pictures\??????rc*." *.txt 
call "F:\meter_pictures\combine.bat"
penpen

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Run a batch file within batch file using VBA

#6 Post by ShadowThief » 13 Feb 2018 13:10

Yes, all I wanted was the "rem" to be removed, not the entire line.

wasimsono
Posts: 11
Joined: 03 Apr 2017 06:06

Re: Run a batch file within batch file using VBA

#7 Post by wasimsono » 13 Feb 2018 22:03

Thanks for your reply.

Now I used following code:

Code: Select all

@echo off
ren "F:\meter_pictures\??????rc*." *.txt 
call "F:\meter_pictures\combine.bat"
but only first line executed i.e.

Code: Select all

@echo off
ren "F:\meter_pictures\??????rc*." *.txt 

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Run a batch file within batch file using VBA

#8 Post by ShadowThief » 14 Feb 2018 03:14

Is the rename actually working correctly?

wasimsono
Posts: 11
Joined: 03 Apr 2017 06:06

Re: Run a batch file within batch file using VBA

#9 Post by wasimsono » 14 Feb 2018 03:58

yes, rename working correctly.

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Run a batch file within batch file using VBA

#10 Post by ShadowThief » 14 Feb 2018 04:12

https://stackoverflow.com/questions/944 ... g-properly suggests that VBA calls batch scripts from a certain directory. Try sticking a

Code: Select all

pushd %0
after the first line in combine.bat

Post Reply