Link to home
Start Free TrialLog in
Avatar of selhamawy
selhamawy

asked on

Invoking shell from vb and usnig the output

I am trying to run a program in vb and use the output in the vb program. for example I am trying to do something like the following.

Dim x as String
x = Shell ("echo hello")

However i am getting a double returned when I want the string hello.

This is the original code. It is giving me an error that the file cannot be found. It stops at the place where it opens the new file.

    ChDir "Y:\essbase\bin\"
    tempName = "java Login " & server & " " & user & " >Y:\essbase\templates\temp.txt"
    Sheets(ParamSheetName).Range("IV65536").Value = tempName
    Shell tempName
    Workbooks.Open FileName:="Y:\essbase\templates\temp.txt"
    Workbooks("mr1.xls").Range("IV65536").Value = Workbooks("temp").Range("A1").Value


Thanks.
Avatar of rspahitz
rspahitz
Flag of United States of America image

The shell command tells VB to tell Windows to run a process and have Windows give it a windows ID number in return (which is passed as a double...or I thought it was a long.)

What you want is something like this:

x = shell("Echo hello > output.txt")
open "output.txt" for input as #1
line input #1, TextInfo$
close 1
msgbox TextInfo$
Avatar of Richie_Simonetti
ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>DO NOT accept this comment as an answer.

Dan, are you in the top 20 yet?  LOL
I've got a ways to go.  All of my VB points are due to this sort of mistake.  I now have 3963 VB points...  

When I'm done with the clean up I vow to give them to charity.  In the meantime, I drop the VB Good Answer emails into a folder so I can list them as a group in the cleanup TA.
-- Dan
>I now have 3963 VB

Soon this account will be eligible for EE-Pro! ;)
Avatar of Netminder
Netminder

Incorrect comment accepted as answer. Per DanRollins' recommendation:

Richie_Simonetti: points for you at https://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20328904
rspahitz: points for you at https://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20328905

Netminder
CS Moderator