LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

console app from labview VI



Hi,

I have a VI which I have turned into an EXE and it works fine (as a dialog-based app). I now want to use this EXE as a console app -- be able to give the input AND receive the resulting output on the command prompt. How can I do this?

I know how to pass in arguments to my EXE from command line. The problem is how do I output the result (bunch of strings) back to the command prompt?

One solution I guess is to build a DLL from my VI and then create a console app in VC++ calling this dll in it.

Any other ideas? examples?

TiA!

Khalid


0 Kudos
Message 1 of 12
(8,388 Views)
Two other ideas:1) The ugly one. Have the VI save its output to a file and then use the DOS command type to put the data on the command line. The command to call the VI and retreive the results could be put in a *.bat file.2) Write a DLL (or find out what the system call is) to write strings to the command prompt window, then call this DLL from within LV.I'm curious, why you need to be able to run things from the command prompt?Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 12
(8,388 Views)
The VI in question is not a real-app .. it's a handy tool I wrote to connect to the Net (using DataSocket VIs) and retrieve some data for personal use. I find it will be much nicer if I can just execute this from the command prompt and get the results back in the console window.

Thanks for the ideas tho'.

Khalid

0 Kudos
Message 3 of 12
(8,388 Views)
Hi,

If it is a windows app, you can read the command line, just line you would
in another language. This is tricky, because the GetCommandLine api works
with an array of strings, where each element is \00 delimited, and the last
element is \00 \00 deleimited.

For the output, I have no idea...

If you want a VI to read the command line, let me know your email address.
But be aware that the command line returns "LabVIEW.exe" when it's called
from the development environment. If you have started LabVIEW by dubble
clicking a VI in the windows explorer, it says "LabVIEW.exe "c:\vi
path\vi.vi"" (or something like this).

Regards,

Wiebe.


"Khalid" wrote in message
news:506500000008000000327A0000-1042324653000@exchange.ni.com...
>

> Hi,
>
> I have
a VI which I have turned into an EXE and it works fine (as a
> dialog-based app). I now want to use this EXE as a console app -- be
> able to give the input AND receive the resulting output on the
> command prompt. How can I do this?
>
> I know how to pass in arguments to my EXE from command line. The
> problem is how do I output the result (bunch of strings) back to the
> command prompt?
>
> One solution I guess is to build a DLL from my VI and then create a
> console app in VC++ calling this dll in it.
>
> Any other ideas? examples?
>
> TiA!
>
> Khalid
>


0 Kudos
Message 4 of 12
(8,388 Views)
Hi,

For the output...

Use GetStdHandle, kernel32 to get a handle, (handle GetStdHandle(long
param), use -11 for parameter);
Use WriteFile, kernel32 to write a string (long WriteFile(long handle, CStr
message, long length, long *written, long overlapped));

It actually works!

Regards,

Wiebe.

"Wiebe@AIR" wrote in message
news:3e6ef96f$0$157$e4fe514c@dreader8.news.xs4all.nl...
> Hi,
>
> If it is a windows app, you can read the command line, just line you would
> in another language. This is tricky, because the GetCommandLine api works
> with an array of strings, where each element is \00 delimited, and the
last
> element is \00 \00 deleimited.
>
> For the output, I have no idea...
>
> If you want a VI to read the command line, let me kn
ow your email address.
> But be aware that the command line returns "LabVIEW.exe" when it's called
> from the development environment. If you have started LabVIEW by dubble
> clicking a VI in the windows explorer, it says "LabVIEW.exe "c:\vi
> path\vi.vi"" (or something like this).
>
> Regards,
>
> Wiebe.
>
>
> "Khalid" wrote in message
> news:506500000008000000327A0000-1042324653000@exchange.ni.com...
> >

> > Hi,
> >
> > I have a VI which I have turned into an EXE and it works fine (as a
> > dialog-based app). I now want to use this EXE as a console app -- be
> > able to give the input AND receive the resulting output on the
> > command prompt. How can I do this?
> >
> > I know how to pass in arguments to my EXE from command line. The
> > problem is how do I output the result (bunch of strings) back to the
> > command prompt?
> >
> > One solution I guess is to build a DLL from my VI and then create a
> > console app in VC++ calling this dll in it.
> >
> > A
ny other ideas? examples?
> >
> > TiA!
> >
> > Khalid
> >


>
>

0 Kudos
Message 5 of 12
(8,388 Views)
Hi Wiebe,

I saw this discussion a little bit late. I think it should be able to open the standard files for console input and output in LabVIEW. These files are known for a C programmer as stdin and stdout which are normally macros to point to handles in the C runtime environment. The real names in Windows are $CONIN and $CONOUT. Maybe you can open them with the file open function in LabVIEW and read / write from / to them.
Waldemar
Waldemar

Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
Don't forget to give Kudos to good answers and/or questions
0 Kudos
Message 6 of 12
(8,388 Views)
Hi,

It doesn't work... I think the LabVIEW File Open checks too much (like if it
is a valid path). I tried this before with COM1 as input, it also doesn't
work.

Anyway the method using GetStdHandle does work. I also experimented with
AllocConsole, this display the console window. Using the WriteFile, you can
actually display text in the new console window.

Now the tricky part... finding any use for this all....

Regards,

Wiebe.


"waldemar.hersacher" wrote in message
news:50650000000500000033DB0000-1042324653000@exchange.ni.com...
> Hi Wiebe,
>
> I saw this discussion a little bit late. I think it should be able to
> open the standard files for console input and output in LabVIEW. These
> files are known for a C progra
mmer as stdin and stdout which are
> normally macros to point to handles in the C runtime environment. The
> real names in Windows are $CONIN and $CONOUT. Maybe you can open them
> with the file open function in LabVIEW and read / write from / to
> them.
> Waldemar
0 Kudos
Message 7 of 12
(8,388 Views)

Hi Wiebe,

 

Thanks for your inputs on how to get command line's handle to send data to console. 

I am trying to hold command prompt till my LabVIEW application sends some response back to console.

Is there any to hold it (Not letting write anything on that command prompt) and once response ready, send data to console and release it?

 

 

Any input is appreciated.

 

Thanks in advance,

Ashwini A Pandit

Thanks and Regards,
Ashwini A Pandit
Wired-in Software Pty Ltd
0 Kudos
Message 8 of 12
(1,735 Views)

@AshwiniWini wrote:

 

I am trying to hold command prompt till my LabVIEW application sends some response back to console.

Is there any to hold it (Not letting write anything on that command prompt) and once response ready, send data to console and release it?


Not sure what you are asking for here. You use a WriteFile() call to write the string/bytes/bananas or oranges to that stdio handle that you got. You surely can decide WHEN you write that information to that handle!

 

If it is about writing from the other side before your app had a change to answer the previous command, well that it something your other side needs to manage. It should of course wait on some response before spamming its side of the command line interface again with the next thing. Even if it doesn't, your LabVIEW app ultimately is in control when it will read again from the input pipe (yes that is what those handles basically are), so if you are not ready to read the next command because you are still working on the previous one, just don't read it yet. The pipe will do some buffering, but of course not indefinitely. 

Rolf Kalbermatter
My Blog
0 Kudos
Message 9 of 12
(1,722 Views)

Hi Rolf,

 

Thank you for your response.

 

When I write string to command prompt, It will call and execute LabVIEW exe. I am expecting it should not let me write on that command prompt, till LabVIEW returns some response.

In attached screenshot, you can see i am pressing enter key while LabVIEW is executing command in background.

AshwiniWini_2-1680478590957.png

 

To write to command prompt, i am using Kernal32 dll library:

AshwiniWini_1-1680478263606.png

Is there any way or property of Kernal32 dll to hold console?

 

Thanks,

Ashwini A Pandit

Thanks and Regards,
Ashwini A Pandit
Wired-in Software Pty Ltd
0 Kudos
Message 10 of 12
(1,694 Views)