DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

How run a batch file from VBS script?

I have written a script in which I create a batch file that I want to run. Running it from the Start menu with "Run..." works fine but I would like to do it automatically from the script. I can't find a command that works but I am a beginner, so I'm hoping someone's got a solution?!
0 Kudos
Message 1 of 9
(8,990 Views)

Please try to use the function "ExtProgram". As you will see from the online help, it allows to starts an executable and it also supports running a batch file.

Andreas

0 Kudos
Message 2 of 9
(8,983 Views)

Perfect! I haven't had the chance yet to try it out with the right file but it seems to be working the way I want.

Thank you!

/Malin

0 Kudos
Message 3 of 9
(8,979 Views)
Hello again!
 
It worked fine just writing Call Extprogram(variables for path and file name), thank you!
 
However, now I've done some other changes in the program and the Extprogram suddenly stopped working. The prompt pops up but it doesn't run the batch file. It's strange since I didn't change anything on this particular line. Could it be that I'm in the wrong folder or something? I've tried writing the whole path instead of using variables but it doesn't help.
 
Thanks in advance for help!
/Malin
0 Kudos
Message 4 of 9
(8,724 Views)

Hi Malin,

Try adding explicit " characters around your DOS path, the same way you would in a DOS window.  If the file path has spaces in it, this is the only way to get it to work:

Call ExtProgram("""C:\My Folder\My Batch File.bat""")

Brad Turpin
DIAdem Product Support Engineer
National Instruments

0 Kudos
Message 5 of 9
(8,707 Views)

Hi again!

 

Thank you for your help but I've just discovered that my problem probably doesn't have to do with the way that I call for the batch file. It's more like this:

The batch file is run but it only does its job some of the times... The batch contains one name of a converter application (Convert.exe) and the names of some databases and files. I've been told that the conversion should work if Convert.exe is located in the same folder as the files. Which it also does, if I run the batch from "Run..." but not from my code.

 

I had it working for a while when I had fiddled (as I said, I'm a beginner at this) with setting some drives, such as userDrv and changing some paths in the script settings. Since I didn't really know what I was doing though, I didn't save these settings when closing down DIAdem and now it's not working again. When it worked, it only worked for the file where my .VBS was saved. The point of the program is to convert files in different folders so that wasn't enough.

 

Just for clearity: I can't write the name as "C:\My Folder..." because the batch file name and the folder it is situated in is different each time so I have variables for the path and the batch, but that part seems to work. (Call ExtProgram(batFilename_) where batFilename_ includes the path).  

 

So I guess what I need to understand is how the different drives work or maybe I need to somehow change my path settings?

0 Kudos
Message 6 of 9
(8,694 Views)

Hi Malankoal...,

 

Just for completeness, you can still add the extra " characters even if your file path is stored in a variable:

 

Call ExtProgram("""" & batFilename_ & """")

 

But I'll move on from there because you said the batch file is being called OK every time.  I'm no DOS or batch file expert, but if you say that your batch file needs to be in the same directory as the data files it's supposed to process, then if it were me I would copy the batch file into the data file directory with FileCopy(), run the batch file in the data file directory with ExtProgram(), then delete the batch file from that directory with FileDelete().

 

Brad Turpin
DIAdem Product Support Engineer
National Instruments

0 Kudos
Message 7 of 9
(8,680 Views)

I tried keeping all the files and programs in the same folder already, though, and it still doesn't work. But maybe it's a DOS problem more than a DIAdem one...  Thank you guys for taking time to help me!

 

I'll try and define my problem better if I ask again.

 

/Malin

0 Kudos
Message 8 of 9
(8,666 Views)

Hello Malin!

 

The DOS concept of a working directory might be the source of your problem. Have a look on this article to get an idea how to solve it.

 

Matthias

Matthias Alleweldt
Project Engineer / Projektingenieur
Twigeater?  
0 Kudos
Message 9 of 9
(8,652 Views)