LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

using "cmd /c net name" with LabWindows cvi and get the answer to the cvi variables

Hi,
 
I tried to use the cmd.exe command - "net name" or "net user" with the CVI.
There is the system() command, or the LunchExecutable() function, which works, but I need the return the "answer" from the cmd.exe windows to the CVI variables.
I know that it can be done with LabView (I used to do it, and it works) but this time I have only CVI ...  😞
 
Thank you,
 
Trz. 
0 Kudos
Message 1 of 11
(6,513 Views)
Perhaps you could use the re-direct operator to send the output of the command to a file. Then simply read the file into CVI afterwards.

    system ("cmd /c some_prog.exe > logfile.txt ");
JR
Message 2 of 11
(6,514 Views)

Thanks, It work well.

But is there any way to fill it to variable without the need to save & read the txt file?

 

Trz

0 Kudos
Message 3 of 11
(6,492 Views)
Not that I'm aware of. Within a command interpreter session, the return value from an executable can be manipulated using ERRORLEVEL, so it might be possible to contrive some mechanism in a batch file which passed this information back through an existing environment variable, which CVI could retrieve via the SDK call GetEnvironmentVariable(). Another possibility is to write a program to set a registry key in a similar manner, but both these approaches seems likely to end up being much messier that the simple file transaction.
 
JR
0 Kudos
Message 4 of 11
(6,484 Views)
there is no way to directly interpret the output of the command into variables, you will have to interpret it yourself.

but using functions from the windows SDK, there is a way to redirect the standard input and output handles of a child process so that you can directly read the output of your command without writing it to a file first. the method is to create a pipe, then creating a child process using CreateProcess, setting the standard output handle to the handle of the pipe in the STARTUPINFO structure.

i may not have been clear, but read this article: Creating a Child Process with Redirected Input and Output

(as a side note: writing the output of the command to a file then reading the file is bad practice and particularly unsafe since an instance of your application may overwrite the result of another instance of your application running at the same time. also the file you specify as a redirection in your command may not be writtable or the path specified may be invalid, causing the command to fail without you noticing it.)
0 Kudos
Message 5 of 11
(6,476 Views)


dummy_decoy wrote:

(as a side note: writing the output of the command to a file then reading the file is bad practice and particularly unsafe since an instance of your application may overwrite the result of another instance of your application running at the same time. also the file you specify as a redirection in your command may not be writtable or the path specified may be invalid, causing the command to fail without you noticing it.)


Well, it was a simple question which deserved a simple answer. If the application is likely to run more than one instance at a time, then the ANSI function tmpnam() could be used to ensure that the text file names used do not clash between concurrent instances. As for invalid or non-writable paths, even the most rudimentary testing of the software would reveal such basic errors. It would be poor software indeed which did not notice a missing file!

JR

0 Kudos
Message 6 of 11
(6,468 Views)
jr_2005 wrote:
"If the application is likely to run more than one instance at a time, then the ANSI function tmpnam() could be used to ensure that the text file names used do not clash between concurrent instances. As for invalid or non-writable paths, even the most rudimentary testing of the software would reveal such basic errors. It would be poor software indeed which did not notice a missing file!"

totally agreed ! but i see soooooo many many many applications which are sooooooo plagued with bugs like this, which are only due to the inexperience of the people who wrote them (or their lazyness to find a better solution), that i thought it was important to note that point.

(agreed as well for the simple answer to the simple question... i should not see too much complications in the problems exposed to me, here and anywhere else)
0 Kudos
Message 7 of 11
(6,458 Views)

Hi,

I'm trying to get handle to the cmd -  so that performing printf would not print to the stdio but to the command line,

I've read the link about the childprocess, do you have a simple example for how to use it?

thanks,

Noa

0 Kudos
Message 8 of 11
(5,996 Views)
first of all, i would say that this deserves a new thread.

i am not sure of what you want to do. can you give us more details, please ?

note that, if you want printf to work with a standard console, use the 'create console application' option in the project settings.
0 Kudos
Message 9 of 11
(5,991 Views)

Hi,

I'm trying to do the following -

from my computer (windows xp) I'm opening a connection to Linux on another computer using plink.

now, from the Linux computer I would like to connect to some ftp server and retrieve a file from there to the Linux computer.

it is simple to do it manually but I'm trying to write an automatic code for that...

do you have any ideas?

thanks,

Noa

0 Kudos
Message 10 of 11
(5,976 Views)