ARPFre Posted March 22, 2023 Posted March 22, 2023 Could you please guide me why it's wrong in my Run, below? The command works normally in CMD, but I am not able to transport it to AutoIt. What I wanted is just to get the result to throw each comma from the CSV into a different variable. But I'm still stuck on the CMD. The command is = wmic /node:127.0.0.1 ComputerSystem get DNSHostName, ChassisSKUNumber, Domain, Manufacturer, Model, UserName /format:csv | find /v "Name" #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WINAPI.au3> #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> $iPID = Run('wmic /node:127.0.0.1 ComputerSystem get DNSHostName, ChassisSKUNumber, Domain, Manufacturer, Model, UserName /format:csv | find /v "Name"', "", @SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD) ProcessWaitClose($iPID) $sOutput = StringStripWS(StdoutRead($iPID), $STR_STRIPLEADING + $STR_STRIPTRAILING) MsgBox(0,0,$sOutput,0)
Developers Solution Jos Posted March 22, 2023 Developers Solution Posted March 22, 2023 probably only adding @COMSPEC /c will do it. (untested) $iPID = Run(@comspec & ' /c wmic /node:127.0.0.1 ComputerSystem get DNSHostName, ChassisSKUNumber, Domain, Manufacturer, Model, UserName /format:csv | find /v "Name"', "", @SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD) SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
ARPFre Posted March 22, 2023 Author Posted March 22, 2023 @Jos Yes, that worked for me. Please can you explain to me why? I used google translate in the manual and could not find the error.
Developers Jos Posted March 22, 2023 Developers Posted March 22, 2023 You are showing a command you would normally run from the windows command prompt, which is what the added part does. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
ARPFre Posted March 22, 2023 Author Posted March 22, 2023 @Jos Thanks! Thanks. Follow for knowledge the code I'm doing. As it is, it worked. But I want it to read from the variable "$sOutputComputerSystem" , without the need to write it in a TXT. Practicing and studying. #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> $iPIDComputerSystem = Run(@comspec & ' /c wmic /node:127.0.0.1 ComputerSystem get DNSHostName, ChassisSKUNumber, Domain, Manufacturer, Model, UserName /format:csv | find /v "Name"', "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ProcessWaitClose($iPIDComputerSystem) $sOutputComputerSystem = StringStripWS(StdoutRead($iPIDComputerSystem), $STR_STRIPLEADING + $STR_STRIPTRAILING) MsgBox(0,0,$sOutputComputerSystem,0) FileWrite("C:\test\a.txt",$sOutputComputerSystem) Global $2dArray _FileReadToArray("C:\test\a.txt", $2dArray,$FRTA_NOCOUNT,",") _ArrayDisplay($2dArray) For $i =1 To UBound($2dArray) -1 MsgBox(0, '', _ $2dArray[$i][0]) Next FileDelete("C:\test\a.txt")
Developers Jos Posted March 22, 2023 Developers Posted March 22, 2023 Just do a stringsplit() to convert the result output into an array and use the new line character as delimiter. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
ARPFre Posted March 22, 2023 Author Posted March 22, 2023 It's more easy! Thanks so much! #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> Global $2dArray $iPIDComputerSystem = Run(@comspec & ' /c wmic /node:127.0.0.1 ComputerSystem get DNSHostName, ChassisSKUNumber, Domain, Manufacturer, Model, UserName /format:csv | find /v "Name"', "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ProcessWaitClose($iPIDComputerSystem) $sOutputComputerSystem = StringStripWS(StdoutRead($iPIDComputerSystem), $STR_STRIPLEADING + $STR_STRIPTRAILING) ReadComputerSystem() Func ReadComputerSystem() Local $sOutputComputerSystemR = StringSplit($sOutputComputerSystem, ",") For $i = 1 To $sOutputComputerSystemR[0] MsgBox($MB_SYSTEMMODAL, "", $i & " " & $sOutputComputerSystemR[$i]) Next EndFunc
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now