0

I want to call a java jar file using vb script in excel. My file format is "xlsm" where is my vb script code.

When i execute my code, then console comes and go, I do not what is written on console. please have a look at code

Public Function RunProgram( _
program As String, _
Optional command As String = "" _
) As WshExec
Dim wsh As New WshShell
Dim exec As WshExec
Dim oShell
Application.ScreenUpdating = False
Set exec = wsh.exec(program)
Call exec.StdIn.WriteLine(command)
 Set RunProgram = exec
'Application.ScreenUpdating = True
End Function
Public Function evenOdd1(Number As Double) As Double
Call Run
End Function

Public Sub Run()
Dim program As WshExec
Set program = RunProgram("java -jar G:\\excel\\MyTest.jar""Margus") 
'Debug.Print "STDOUT: " & program.StdOut.ReadAll
End Sub

I have tried Application.ScreenUpdating, Application.visible to hold the screen but unable to hold console.. Please help me

1 Answers1

0

When i execute my code, then console comes and go,

Do you mean that a console window (basically cmd.exe) pops up on the screen and then disappears? If that's what's going on, then either (a) there's a problem with your command (bad syntax, can't find java, etc.) so the system exits immediately without running your command; (b) the system ran the command, but java didn't understand the command's arguments, and is exiting immediately; or (c) your Java program runs properly and exits immediately (this is unlikely -- Java takes at least a few hundred milliseconds to load).

To determine which is the problem, you might try using this as your command (instead of whatever you're generating):

ping 1.1.1.1 -n 1 -w 5000

That will open a command prompt (aka "console window"), try to ping the (invalid) IP address 1.1.1.1, and wait 5 seconds for a response. The command should stay up for 5 seconds while it waits for a response.

If the command prompt does stay up for 5 seconds, then you've confirmed that the problem is the command you're trying to run. Try printing the command you're trying to run to a VB console and running it in cmd.exe to see what's wrong.

sigpwned
  • 6,957
  • 5
  • 28
  • 48