Jump to content

Variable Relying on Messageboxes?


Go to solution Solved by Gianni,

Recommended Posts

Good day.
As part of my learning process for AutoIt, I'm working to convert every Batch I've written to this new [for me] language.
I've run into a bit of trouble with one in particular. The original batch (if it matters) used this bit of code: 

REM This will search the drive letter of our USB and set it = %letter%
  FOR /f %%d in ('wmic volume get driveletter^, label ^| findstr "[MyUSB]"') DO set letter=%%d

([MyUSB] would be replaced with the name of my thumb drive manually)

The purpose of this, as the comment says, was to find the thumb drive's drive letter, and assign it to the variable %letter%.

I've mostly recreated this in AutoIt, but for some reason my script seems to be relying on the existence of two MsgBox lines for the third to have any value (see below):

#include <Constants.au3>

Local $GetLet = Run(@ComSpec & " /c wmic volume get driveletter, label | findstr Professor", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

If @error Then
    Exit
Else
    ;First message box I need to be rid of:
    MsgBox(0, "MSGBOX I WANT TO GET RID OF #1", $GetLet, .5)
    Local $FullName = StdoutRead($GetLet)
    Global $drLetter = StringTrimRight($FullName, 31)
    ;Second message box I need to be rid of:
    MsgBox(0, "MSGBOX I WANT TO GET RID OF #2", $drLetter, .5)
EndIf

;Message Box I want to keep (for now...)
MsgBox(0, "Drive Letter:", "The Drive Letter is: " & $drLetter)

NOTE: 'Professor' (In the first string) is the name of the test drive I am using.

You see, if I remove either of the first two message boxes: The third will not display the variable $drLetter. What's going on here?

Thanks, Josh

Edit: Wording.

Edited by TheProfessor
Link to comment
Share on other sites

  • Solution

Hi theprofessor,

why have you used those 2 msgbox #1 and #2?
i think them are not necessary at all

$GetLet in your script contains "The PID of the process that was launched" and not the dos output of your command

to get the output of your DOS command you have not to use msgbox
use a stdout reading loop until you get an @error, someting like this:

#include <Constants.au3>
Local $GetLet, $FullName
$GetLet = Run(@ComSpec & " /c wmic volume get driveletter, label | findstr Professor", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

; first retrieve the whole dos output of your command
Do
    $FullName &= StdoutRead($GetLet)
Until @error

; now $FullName contains the complete output
ConsoleWrite("> " & $FullName & @CRLF)

; use the output as you like
Global $drLetter = StringTrimRight($FullName, 31)
MsgBox(0, "Drive Letter:", "The Drive Letter is: " & $drLetter)

(I do not enter into the matter of your dos command)

bye

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

PincoPance,

Thank you for your response. My final script (now one logical component from being completed) will not contain any messageboxes; I just use them instead of ConsoleWrite (as I am a newb). I was trying to remove them, and that's when I noticed the dilemma (of my $drLetter variable not being set). 

Your solution worked perfectly: Cheers for the assistance.

Edited by TheProfessor
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...