Jump to content


Photo
* * * * * 1 votes

Running a LabVIEW EXE from the Console


  • Please log in to reply
30 replies to this topic

#21 Jim Kring

Jim Kring

    packages everywhere!

  • JKI
  • 1,901 posts
  • Location:Lafayette, CA
  • Version:LabVIEW 2011
  • Since:1995

Posted 12 January 2010 - 12:01 AM

Weird. I get nothing under XP when calling from either LV2009 or 8.6.1. Maybe this is an XP issue. Can you try this on an XP machine and confirm?


It works fine for me in XP SP3, too. Maybe you need to install/upgrade .NET?

#22 John Lokanis

John Lokanis

    The 500 club

  • Premium Member
  • 577 posts
  • Location:Seattle, WA
  • Version:LabVIEW 2012
  • Since:1993

Posted 12 January 2010 - 12:04 AM

No joy here. I cannot get anything back from the System Exec call. It does open a console window and I can see the output in the window as I press the write buttons but when I choose exit and close the app's window, nothing is returned to the calling LV VI. Do you have anything special in your exe's ini file?


Weird. I get nothing under XP when calling from either LV2009 or 8.6.1. Maybe this is an XP issue. Can you try this on an XP machine and confirm?


Ok, Now I see what I did wrong. I was calling it like this: 'cmd.exe /c "myapp.exe"'.
That does not work. Interestingly, however, something like this: 'cmd.exe /c dir' does return data to the stdout of System Exec. So, again it appears that you can attach to the console of the caller but System Exec is more like the 'run' command. Still does not explain why redirection does not work.
----------------------------------
John Lokanis
CLA
Twitter: @jlokanis

#23 smenjoulet

smenjoulet

    Very Active

  • Premium Member
  • 125 posts
  • Location:Dallas, TX
  • Version:LabVIEW 2010
  • Since:1992

Posted 12 January 2010 - 12:09 AM

No joy here. I cannot get anything back from the System Exec call. It does open a console window and I can see the output in the window as I press the write buttons but when I choose exit and close the app's window, nothing is returned to the calling LV VI. Do you have anything special in your exe's ini file?

Weird. I get nothing under XP when calling from either LV2009 or 8.6.1. Maybe this is an XP issue. Can you try this on an XP machine and confirm?



No, nothing special in the ini. In fact you don't even need the ini. I'm on XP and Jim has tried it on Win7.

What are you using for the command line in System exec? I wouldn't expect a console Window to open (I don't get one), which leads me to believe you are using cmd /c or start on the command line. Just try the path to the exe and see if that works.

-Scott

EDIT: I see you've already figured it out. I'm working on the redirection issue. If I get it figured out, I'll post the solution.
Simple <> Easy. Just because it may be simple, does not mean it is easy!

#24 Jim Kring

Jim Kring

    packages everywhere!

  • JKI
  • 1,901 posts
  • Location:Lafayette, CA
  • Version:LabVIEW 2011
  • Since:1995

Posted 12 January 2010 - 12:17 AM

Ok, Now I see what I did wrong. I was calling it like this: 'cmd.exe /c "myapp.exe"'.
That does not work. Interestingly, however, something like this: 'cmd.exe /c dir' does return data to the stdout of System Exec. So, again it appears that you can attach to the console of the caller but System Exec is more like the 'run' command. Still does not explain why redirection does not work.


Ya, I use the full path of the EXE as the command.

#25 John Lokanis

John Lokanis

    The 500 club

  • Premium Member
  • 577 posts
  • Location:Seattle, WA
  • Version:LabVIEW 2012
  • Since:1993

Posted 12 January 2010 - 02:12 AM

Ya, I use the full path of the EXE as the command.

So, when calling this from a real console (cmd.exe) you need to use the start command to make the console wait. But, the start command is it's own app so either the AttachConsole does not really attach you to the cmd.exe's console or the GetStdHandle is not the cmd.exe's StdOut. So, redirection fails.
What about using WriteFile instead of WriteConsoleA? That might make the redirection work.
----------------------------------
John Lokanis
CLA
Twitter: @jlokanis

#26 John Lokanis

John Lokanis

    The 500 club

  • Premium Member
  • 577 posts
  • Location:Seattle, WA
  • Version:LabVIEW 2012
  • Since:1993

Posted 12 January 2010 - 02:40 AM

What about using WriteFile instead of WriteConsoleA? That might make the redirection work.

Nope. Back to the drawing board...
----------------------------------
John Lokanis
CLA
Twitter: @jlokanis

#27 smenjoulet

smenjoulet

    Very Active

  • Premium Member
  • 125 posts
  • Location:Dallas, TX
  • Version:LabVIEW 2010
  • Since:1992

Posted 13 January 2010 - 09:34 PM

Nope. Back to the drawing board...


OK, I got piping/redirection to work. The key was some code/info posted on this C# thread.
There are a couple more kernel32 dll calls now, so it's even farther from pure .NET. However, it works pretty good, both from console and System Exec.

Next up: Develop similar method to allow a LabVIEW program to accept input from StdIn.

-Scott

Attached Files


Simple <> Easy. Just because it may be simple, does not mean it is easy!

#28 John Lokanis

John Lokanis

    The 500 club

  • Premium Member
  • 577 posts
  • Location:Seattle, WA
  • Version:LabVIEW 2012
  • Since:1993

Posted 13 January 2010 - 10:17 PM

OK, I got piping/redirection to work.

Sweet! This works for me. Only caveat is I cannot call it from the command line using start /wait to force it to wait until completion. However, calling it with "cmd /c myapp.exe" does work, will wait and redirection works too.

Thanks! now to try this in my real world application and see if Python likes it!
----------------------------------
John Lokanis
CLA
Twitter: @jlokanis

#29 John Lokanis

John Lokanis

    The 500 club

  • Premium Member
  • 577 posts
  • Location:Seattle, WA
  • Version:LabVIEW 2012
  • Since:1993

Posted 14 January 2010 - 07:43 PM

now to try this in my real world application and see if Python likes it!


Confirmed! This solution works in all my test cases for my Console app! :thumbup1: Thanks to smenjoulet! :worshippy: I owe you a beer at the next NI Week! :beer_mug: :beer_mug: :beer_mug:
----------------------------------
John Lokanis
CLA
Twitter: @jlokanis

#30 faiob

faiob

    One hit wonder!

  • Members
  • 1 posts
  • Version:LabVIEW 8.2
  • Since:2002

Posted 06 March 2012 - 04:41 PM

Please, can you save
  • Posted Image Write Std Out with Redirection.vi for Labview 8.2?


#31 asbo

asbo

    I have no idea what you're talking about... so:

  • V I Engineering, Inc.
  • 1,273 posts
  • Version:LabVIEW 2011
  • Since:2008

Posted 06 March 2012 - 05:27 PM

Attached File  Write Std Out with Redirection.LV8.0.vi   27.59K   74 downloads