Jump to content
News about the LabVIEW Wiki! Read more... ×
mje

Printing to the Standard Output

Recommended Posts

Here's a quick one: Is there a native way in LabVIEW that I can first of all tell if my built application was launched via the command line? Also, is there a native way to print to the standard output if it was?

Share this post


Link to post
Share on other sites

Here's a quick one: Is there a native way in LabVIEW that I can first of all tell if my built application was launched via the command line? Also, is there a native way to print to the standard output if it was?

Native no. Here's a post a little while back that does what you want using magic. :shifty:

Share this post


Link to post
Share on other sites

Here's a quick one: Is there a native way in LabVIEW that I can first of all tell if my built application was launched via the command line?

Can any executable do this? I don't recall ever seeing one able to differentiate. You can hack around it by enabling command line arguments in your build and then checking App:Command Line Arguments - you would have to enforce command line arguments in one scenario or the other to be able to figure how the executable was launched, however.

I'm curious, what's your use case? :)

Share this post


Link to post
Share on other sites

Native no. Here's a post a little while back that does what you want using magic. :shifty:

http://lavag.org/top...dpost__p__70995

Thanks! I forgot about that gem...

Can any executable do this? I don't recall ever seeing one able to differentiate.

I'm not aware of being able to do it in other languages/RTEs. You never know though, I thought maybe the presence (or lack) of a standard output might provide a hint as to how the executable was invoked.

I'm curious, what's your use case? :)

Nothing special. I have a LabVIEW executable that responds to command line arguments. I wanted to print out a usage summary if invoked without arguments. Also want to print out debug messages over the course of execution and allow redirection to files etc. I wasn't sure that if there was a stdout in LabVIEW if printing to it would force it to show if a command line wasn't used. Seems like a moot concern now though.

I'll review the other thread again and see if I come up with anything.

Thanks again,

-m

Share this post


Link to post
Share on other sites

Nothing special. I have a LabVIEW executable that responds to command line arguments. I wanted to print out a usage summary if invoked without arguments. Also want to print out debug messages over the course of execution and allow redirection to files etc. I wasn't sure that if there was a stdout in LabVIEW if printing to it would force it to show if a command line wasn't used. Seems like a moot concern now though.

Maybe it could be somehow realizable with OpenG Pipes... Just loose thought.

Share this post


Link to post
Share on other sites

Haven't played with pipes yet (too short on time), but I gave up on ever obtaining the standard output. Research into Windows architecture seems to indicate that GUI applications just aren't initialized with the Standard I/O/E streams, so it seems futile to obtain them. I was hoping that launching the application from a command line would make the OS initialize the streams, but no luck so far...

So I settled on creating my own console. Kudos goes to the several posts referred to above, they helped point me in the right direction. Not sure how this will translate if it's plopped in a 64-bit application, if someone cares to test it that'd be great (my guess is WoW64 will take care of everything, but you never know...):

post-11742-0-59743700-1291989547_thumb.p

It's a one-stop shop for console output. The snippet will create a console if one doesn't exist already, then write a string to it. You need to supply your own CRLF sequences. The snippet will also change the window title if you supply one.

One bad thing about consoles is they're meant to be attached to a process, and when the one (and only) console exits, the OS kills the process. Hence the VI also disables the Ctrl+C/Alt+F4/Close commands/handlers. This means (unfortunately) that once open, the console will persist until the process that created it returns. If you're in the IDE, it means you need to quit the entire IDE. For an application, the console will vanish when your application returns. Even gracefully detaching your process from the console (via kernel32.dll:FreeConsole) will cause your process to terminate, as far as I can tell...

Cheers,

-m

  • Like 1

Share this post


Link to post
Share on other sites

Not sure how this will translate if it's plopped in a 64-bit application, if someone cares to test it that'd be great (my guess is WoW64 will take care of everything, but you never know...):

Does what it says on the tin in LV x64thumbup1.gif

Edited by ShaunR

Share this post


Link to post
Share on other sites

Do you know what a non-disclosure agreement is? Well you agree to one when you sign up for a LabVIEW beta, and you can be subject to whatever NI feels that are legally allowed to come after individuals for. One such restriction is to not discuss beta topics outside of approved areas. This can have a real negative impact on NI's business.  LAVA is about minimal censorship and unless you, or NI complain I won't be editing your post, but if I were you I'd edit your post, or ask them to be edited.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

By using this site, you agree to our Terms of Use.