DanM711
asked on
how to call an exe file from vb and get output values (exe created in matlab)
I have a matlab function:
function output1, output2, output3 = test(a,b)
output1 = a;
output2 = b;
output3 = a + b;
end
which i have compiled into an exe file - test.exe
i wish to call this exe file from my vb6 application and store the 3 returned values into variables in vb.
Can anyone provide me with the vb code to do this?
I need this ASAP, so there are 500 points up for grabs!!!
function output1, output2, output3 = test(a,b)
output1 = a;
output2 = b;
output3 = a + b;
end
which i have compiled into an exe file - test.exe
i wish to call this exe file from my vb6 application and store the 3 returned values into variables in vb.
Can anyone provide me with the vb code to do this?
I need this ASAP, so there are 500 points up for grabs!!!
how does the matlab exe return the data? to the "command prompt"?
ASKER
when i run the matlab exe, nothing appears at the command prompt. I can get matlab to print the values to the command prompt if i want. Is there a way to get vb to read this? although i'm sure there must be a way to retrieve the values without having to print them out.
what happens if at the command prompt you type
test.exe > c:\test.txt
is there a file 'c:\test.txt' that gets created ?
and does it have the values in it ?
if so you can let your vb program read that file to get at the values
test.exe > c:\test.txt
is there a file 'c:\test.txt' that gets created ?
and does it have the values in it ?
if so you can let your vb program read that file to get at the values
ASKER
nothing gets written into the file. But i don't want to have to get vb reading files. There must be a way to get the output values....
ok
you say you have a program 'test.exe'
what does that program do ?
how do you get the input values (a,b) into test.exe ? on the command line ?
and how does test.exe give back its output (a,b,a+b) ? to the console window ?
you say you have a program 'test.exe'
what does that program do ?
how do you get the input values (a,b) into test.exe ? on the command line ?
and how does test.exe give back its output (a,b,a+b) ? to the console window ?
>>But i don't want to have to get vb reading files. There must be a way to get the output values....
You can do this using PIPES.
Basically you change the STDIN and STDOUT of a exe when you create the process using CreateProcess (). This allows you to programically send and receive output from CONSOLE based applications, make sense?
Check out this download: (DONT RELY ON THE CODE, IT DOES NOT PROVIDE DECLARATIONS, DOWNLOAD THE WHOLE PROJECT).
http://vb-helper.com/howto_capture_console_stdout.html
Good Luck.
Brian
You can do this using PIPES.
Basically you change the STDIN and STDOUT of a exe when you create the process using CreateProcess (). This allows you to programically send and receive output from CONSOLE based applications, make sense?
Check out this download: (DONT RELY ON THE CODE, IT DOES NOT PROVIDE DECLARATIONS, DOWNLOAD THE WHOLE PROJECT).
http://vb-helper.com/howto_capture_console_stdout.html
Good Luck.
Brian
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi,
First of all u must be sure to make a activeX .exe not a standard exe.
Make the test.exe as activeX .exe ( properties -> ProjectType -> ActiveX exe )
Then make sure there are some public functions in the activeX .exe
Example:
public function givemesomeoutput (output1, output2, output3) as double
givemesomeoutput = output1 + output2 + output 3
end function
Now u can lay a reference in some other vb program to the test.exe ( just browse to the location of the exe )
When u have successfully make a reference to the test.exe, u can call the function givemesomeoutput
Goodluck
Hans
First of all u must be sure to make a activeX .exe not a standard exe.
Make the test.exe as activeX .exe ( properties -> ProjectType -> ActiveX exe )
Then make sure there are some public functions in the activeX .exe
Example:
public function givemesomeoutput (output1, output2, output3) as double
givemesomeoutput = output1 + output2 + output 3
end function
Now u can lay a reference in some other vb program to the test.exe ( just browse to the location of the exe )
When u have successfully make a reference to the test.exe, u can call the function givemesomeoutput
Goodluck
Hans
If you don't want to use file I/O to communicate with VB, your other option is to use COM or DDE. According to the MATLAB website, MATLAB is capable of using these technologies, as described in the following reference:
http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/f27154.html
You might also post this question on the MATLAB forum, to see if someone else has done this before:
http://newsreader.mathworks.com/WebX?14@@/comp.soft-sys.matlab
My guess is there are going to be very few people here on EE who are also MATLAB users.
HTH-Jon
http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/f27154.html
You might also post this question on the MATLAB forum, to see if someone else has done this before:
http://newsreader.mathworks.com/WebX?14@@/comp.soft-sys.matlab
My guess is there are going to be very few people here on EE who are also MATLAB users.
HTH-Jon
can't you just use
shell test.exe > c:\test.txt from inside Your vb function:
Function Shell(PathName, [WindowStyle As VbAppWinStyle = vbMinimizedFocus]) As Double
shell test.exe > c:\test.txt from inside Your vb function:
Function Shell(PathName, [WindowStyle As VbAppWinStyle = vbMinimizedFocus]) As Double
@oleggold,
He doesnt want to have to parse text files for the output of the program.
He doesnt want to have to parse text files for the output of the program.
indeed
and he even doesnt want to tell us how that program gets its input,or how it gives its output
so what do you want to do ?
and he even doesnt want to tell us how that program gets its input,or how it gives its output
so what do you want to do ?
>>so what do you want to do ?
We have to wait until he explains his situation further.
We have to wait until he explains his situation further.
ASKER
The input is in the call within vb.
i'm guessing that parsing text from a file will slow the vb app.
clivious's approach sounds promising, would be interessted to see the corresponding vb code.
I'm also going to be checking out the approach sent by BrianGEFF719
i'm guessing that parsing text from a file will slow the vb app.
clivious's approach sounds promising, would be interessted to see the corresponding vb code.
I'm also going to be checking out the approach sent by BrianGEFF719
As I said get that code from RAC, that reads Matlab's output that MATLAB writes to comamnd line, then you can process the output