LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Command line redirection....

Hi,
 
I am very new to Labwindows and have following questions.
1. I have used createprocess to redirect the command line text to the listbox.  In createprocess, i'm calling an batch file, which inturn calls an executable. If i terminate the process, only cmd.exe is terminated not the executable which is invoked by the batch file. How to terminate this executable which has no PID number.
2. The executable runs for 10 minutes and i am not able to redirect the command line text continously as the function PeekNamedPipe is not able to get data continously.
3. How to pass ctrl-c to the process which invoked cmd.exe so that i can pause my execuatable from running.
 
Regards
Praveen Antony
Message 1 of 9
(5,938 Views)
Hello Praveen

It is expected that your executable launched from the batch file would not terminate when you abort your CVI program.  CVI has no real knowledge of this exe process that is running and has no way of terminating it.  It sounds like you may want to use a different method to call this exe file.  What environment was it developed in?  Have you considered making it part of your CVI project or calling it by more direct means and waiting for it to complete before moving on with your program?  I think you will need to restructure your application a bit to do what you want to do.

Some of the posts on the following discussion forums helpful as they discuss making system calls and launching executables:
http://forums.ni.com/ni/board/message?board.id=180&message.id=762&query.id=121092#M762
http://forums.ni.com/ni/board/message?board.id=180&message.id=18772&requireLogin=False
http://forums.ni.com/ni/board/message?board.id=180&message.id=12088&query.id=121063#M12088

I hope that helps!
Regards,


Marty H.
National Instruments
0 Kudos
Message 2 of 9
(5,899 Views)

Hi Marty,

thanks a lot for the reply



But let me tell u my actual problem
Im trying to run an exe (it’s a c program) that takes command line parameters as input and prints the info using printf statements on the command line.

Just as an ex: say I have test.exe that takes 2 parameters namely employee NAME and ID and prints the entire information of the Employee like date of birth, address etc,
now all I want, is to create a GUI using lab windows, run the exe with parameters from the GUI and wat ever is output by the Exe is to be displayed on a Textbox of the GUI

Here actually I m able to run the exe by creating a batch file (1.bat which in turn calls test.exe with the parameters) and display the output on the text box using PeekNamedPipe as u can see in Process.c file above,
only that the output from the exe is displayed after much delay, which is not acceptable.

Could u suggest where I have gone wrong or wat wud be better way to do this, so that the display is faster.

Note : The test.exe is very big and runs for about 5 mins with lot of data printed on the screen every few seconds.

Thanks and Regards
Praveen

0 Kudos
Message 3 of 9
(5,840 Views)

If you can wait for the exe to terminate before reading its output you could call it via LaunchExecutableEx ( ) redirecting the output to a file, reading back the file after the program has terminated as described in this thread. Since the executable is long lasting, you could start a loop testing if ExecutableHasTerminated ( ) and optionally use TerminateExecutable ( ) to abort it prematurely.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 4 of 9
(5,824 Views)
Hi Robert,
 
i actually want the output of the exe to be displayed on the textbox of GUI in real time.
is this possible??
 
thanks and Regards
praveen
0 Kudos
Message 5 of 9
(5,794 Views)
I think there is no special support in CVI for that task and you have to use the Windows SDK functions to do that.  I hope that http://msdn2.microsoft.com/en-us/library/ms682499.aspx will give you a hint how to start.
0 Kudos
Message 6 of 9
(5,782 Views)
Hi Praveen, I never tried what you are aiming to so I'm afraid I cannot be of any help in this respect.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 7 of 9
(5,774 Views)
i took some time to test the "process.c" file you gave in your first post.

i can see some reasons why the output is slow and delayed:
- you declare a buffer for holding data coming from the pipe which is 8000 byte big (good) then you read data by chunk of 5 bytes (bad !). use sizeof( PipeData ) as the third parameter to PeekNamedPipe and ReadFile. this would GREATLY improve performances (greatly as in 1600 times faster !)
- PeekNamedPipe actually reads data from the pipe into the buffer, so you first read them using PeekNamedPipe, and re-read them using ReadFile. you should set the second parameter to PeekNamedPipe to NULL to disable reading data when peeking. (alternatively, you could create a named pipe in non-blocking mode, but this is discouraged by microsoft)(this should make the output about 2 times faster).
- last, your way of appending to the textbox is wrong: you first read everything, append your text, clear the textbox and write everything back. i can imagine when you have 5minutes of continuous output into your textbox: i hope it will never go beyond the 4KB buffer size you allocated to hold that ! try appending the text, it will be much faster (exp(N) faster where N is the number of lines written in the textbox)

now, Marty_H said:
"It is expected that your executable launched from the batch file would not terminate when you abort your CVI program."
this statement sounds wrong: CreateProcess creates a child process running cmd.exe which in turns creates a child process running the final executable. when aborting the CVI program, every child processes should abort too ! in fact the original posts tells us that cmd.exe does indeed abort but not the final executable. i would suggest to launch the executable without going through a batch file. also check the options for cmd.exe: it should wait gently until everything is finished not exit before the end of the batch. are you sure your batch file does not use the start command to spawn your executable ?

hope this helps...

0 Kudos
Message 8 of 9
(5,733 Views)
Just a suggestion :
 
If the code of the exe file you mention is available, you can use the DDE library of CVI for inter-application data traffic.
I once wrote such a code and we are using it for some time without any problem.
 
Make your GUI code as the server and the other code as a client (you'll need to edit the C-code and re-compile it as an executable  from CVI). When the program is executed it can connect to the server already started by the GUI code.
The exe will then wait for DDE commands from the GUI. When user demands info you send the command through DDE and the exe code will send back the result again through DDE functions. Everthing is immediate, no delays, nothing.
 
The DDE library is not cumbersome and you may come up with your new code within 2 days. There are also some great samples in CVI installation.
 
Hope this helps.
S. Eren BALCI
IMESTEK
0 Kudos
Message 9 of 9
(5,698 Views)