
How do you execute a command-line program, and return the results into a variable?
Hi,
sorry to interrupt, but I'm trying to solve pretty much the exact same
problem. I'm using Excel7.0's VBscript module to create a custom function.
Here's the content of my VBScript:
'***
Function MyFunc(num)
MyFunc = Shell("c:\jdk1.2.2\bin\java.exe Return " & num, 1)
End Function
Sub test()
MsgBox MyFunc(234)
End Sub
'***
Basically, Return is a java program that takes the parameter num.
I know this executes properly because I can see the DOSwindow pop up with
the right result. I, however, want to capture that result and store it in
MyFunc. (Right now the command I have returns stuff like -98263157, but I
think that has more to do with the shell itself than my program?). I tried,
as you suggested (modified for my purposes):
MyFunc = 3D WshShell.Run("c:\jdk1.2.2\bin\java.exe Return " & num)
but the Script editor highlights the 3D and tells me "Expected: End of
Statement"so I'm assuming it's not proper syntax.
I also tried just Shell.Run(...), to which it replied "arguments not
optional" [maybe I have the method signature wrong? what is it in that
case?].
I understand programming well, but am a novice at VB. Please Help, and
don't be afraid to get technical.
thanks,
-Yudes
p.s. also, I have posted other questions to Cnet, but nothing has ever
showed up in my member database, let alone "Open Questions." Once I post
the questions, they disappear. What gives?!
Quote:
> Don't know anything about Regread.exe, but have you tried:
> MyVar =3D WshShell.Run("Regread.exe \\computername")
> MsgBox MyVar
> --=20
> Bill James
> Microsoft MVPDTS
> Free Win9x VBScript Utilities
> http://home.earthlink.net/~wgjames/vbspage/
--
Posted via CNET Help.com
http://www.help.com/