10-09-2019 01:06 AM - edited 10-09-2019 01:20 AM
Hi all,
I am sending commands from LabVIEW to cmd to quiry for USB device location (i.e. Port_xxx.Hub_xxx). The main VI is Launch and Monitor Command2.vi.
I found a code from this forum and modify it to the application i need.
This code sending windows command to powershell in cmd to obtain the device instance path, and use the instance path to enquire the usb location.
However, i found the code sometimes doesn't work properly.
Let's say when i run for the first time, i get what i need but when i run the VI for the second time, what i have sent to cmd doesn't appear on cmd windows. Instead, the cmd windows is like keep flashing abnormally.
If the VI runs properly everytime when i hightlight execution for the subVI Paste Command into Command Window.In this case user should be able to see the USB device location at the output Array.
I have attached the VI here. Can anyone advise on this?
10-09-2019 01:40 AM
Hi 123,
are trying to use the clipboard for data exchange between LabVIEW and a PowerShell window? I don't think this will work reliably…
Why don't you call the PowerShell again with your new command?
Why don't you use the network (localhost) for reliable communication between different processes?
Why don't you even have PowerShell store it's result into a file you can easily read with LabVIEW?
10-09-2019 02:34 AM - edited 10-09-2019 02:45 AM
Hi GerdW,
Why don't you call the PowerShell again with your new command?
I cannot call powershell again for every new command. That is because the cmd will become unstable and i can't see the commands sent from LabVIEW appear on the cmd windows.
Why don't you use the network (localhost) for reliable communication between different processes?
Can you provide some sample VI that using this method? I am sorry as i am not familiar with that. But i would like to try.
Why don't you even have PowerShell store it's result into a file you can easily read with LabVIEW?
Because i did not know other method. Can you show me how to do that?
Best regards,
Crystal
10-09-2019 08:24 AM
In general, if you want to perform several commands with cmd or powershell i'd suggest making a .bat or .ps1 file and call that. That can be done programmatically if need be. As to writing a file, you need to pipe the result to out-file.
From the link below
Get-Process | Out-File -FilePath .\Process.txt
/Y
10-10-2019 04:37 AM
Hi Yamaeda,
I have been using a batch file. But the commands sent doesn't appeared on the cmd windows.
Sometimes it works but sometimes not.
Anyway i have solved my problem by adding a delay in the Paste Command into Command Window.vi.
Best regards,
Crystal