Trouble With Calling A Java Class File From VB Via A Batch File

Nichwee

New member
Joined
Mar 7, 2012
Messages
1
Programming Experience
Beginner
Hello,

I am new to VB programming, using the Visual Studio Express 2010 IDE, and I am having a problem.

I have a VB program that writes a batch file to allow me to run a line of the following format:
java <my class file> [options]

I then run the batch file using the Shell() routine in VB.
When I do this it says it cannot find <my class file>. However if I run the same batch file from a dos prompt it works.

Can anyone explain why it works in a dos prompt but not in the Shell function?
And if you can also suggest any solutions I would be most grateful.

Thank you for your time.
 
Hello

I don't know if this will help but there is a another way of calling an external program through VB. Try Process.Start(FileName), It has 5 different ways to start an external program and I have found it is better than Shell.

You can also declare a new variable as a Process like so:

Dim BatchProcess as New Process
Dim Args as String = "Whatever arguments you may need"

'Add The FileName..
BatchProcess.StartInfo.FileName = "C:\MyBatchProcess.bat"

'Add any arguments you need..
BatchProcess.StartInfo.Arguments = Args

'And then start the process..
BatchProcess.Start()

There are many other flags you can set in the ProcessName.StartInfo that might be of use to you.
You can also wait for the process to end with ProcessName.WaitForExit()

Hope this helps.

Regards
 
Last edited:

Latest posts

Back
Top