Jump to content

Multi vars in run command


thexshadow
 Share

Go to solution Solved by MHz,

Recommended Posts

I'm trying to get a few vars to work in my run command. I removed everything that isnt needed in the script.

Run(@ComSpec & " /c bm.exe -d -o zi2.bms ters.pak ", "",@SW_HIDE)

Now, bm and zi2 are in a folder called stg in the temp directory and ters in on the desktop.

When I try and grab the files from these places it errors out.

Local $tmp = "@TempDir\stg"
Local $dtop = "@DesktopDir"


Run(@ComSpec & " /c " $tmp & "bm.exe -d -o" & $tmp & "zi2.bms" & $dtop & "ters.pak ", "",@SW_HIDE)

Any ideas?

Link to comment
Share on other sites

Yeah. You are all over the place quoting stuff that needs no quotes and others that may need quoting. You just need to get used to know when to quote and when not.

Local $tmp = @TempDir & '\stg'
Local $dtop = @DesktopDir

Run('"' & @ComSpec & '" /c "' & $tmp & '\bm.exe" -d -o "' & $tmp & '\zi2.bms" "' & $dtop & '\ters.pak"', '', @SW_HIDE)

The double quotes are kept in as part of the string while the single quotes help contain the string. Macros work better defined outside of the string being created.

See if that solves your issue. :)

Edit: Added missing &

Edited by MHz
Link to comment
Share on other sites

Yeah. You are all over the place quoting stuff that needs no quotes and others that may need quoting. You just need to get used to know when to quote and when not.

Local $tmp = @TempDir & '\stg'
Local $dtop = @DesktopDir

Run('"' & @ComSpec & '" /c "' $tmp & '\bm.exe" -d -o "' & $tmp & '\zi2.bms" "' & $dtop & '\ters.pak"', '', @SW_HIDE)

The double quotes are kept in as part of the string while the single quotes help contain the string. Macros work better defined outside of the string being created.

See if that solves your issue. :)

 

Yeah, I'm need to get use to the single and double quotes.

Also, Says error in expression when I use what you posted.

Link to comment
Share on other sites

I found that after I looked through the code. >_<

Now, I added a file open dialog, the var does not want to work. It outputs a number.

The file is tree.pak, when I open it, the output is "C:UsersmeDesktop4" instead of "C:UsersmeDesktoptree.pak"
 

Local $GUI  = GUICreate("SoD", 800, 330)
Local $BMSOutput = GUICtrlCreateEdit("", 10,40,780,280, $ES_AUTOVSCROLL + $WS_VSCROLL + $es_readonly)
Local $File = GUICtrlCreateInput("",10,10,500,20)
Local $OpenDialog = GUICtrlCreateButton("Open Pak",515,10,70,22)
Local $Extract = GUICtrlCreateButton("Extract",600,10,55,22)


GUISetState(@SW_SHOW)


SoD()

Func SoD()
   Local $mne,$out
   While 1
      $msg = GUIGetMsg()
      Select
         Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
         Case $msg = $OpenDialog
            $Fileopen = FileOpenDialog("File open", @DesktopDir,"Pak Files (*.pak)")
            GUICtrlSetData($File,$Fileopen)
         Case $msg = $Extract
         $mne = Run('"' & @ComSpec & '" /c "' & @TempDir & '\sod\bm.exe -o -d -v ' & @TempDir & '\sod\zi2.bms ' & $File, '', @SW_HIDE)
         While 1
            $out = StdoutRead($mne)
            If @error then exitloop
            GUICtrlSetData($BMSOutput,$out & @lf,1)
         WEnd
      EndSelect
   WEnd
EndFunc
Edited by thexshadow
Link to comment
Share on other sites

If I renamed $File to $ControlID_Of_Input_Control then you may understand perhaps why you are getting a number. Controls are assigned numbers. You access these controls by these numbers which you will store in variables and then you may want to read information from them later.

Example:

GuiCtrlRead($File)

should read the Input with the ControlID stored in $File. You may then get the text in the Input control rather then the controlID number. :)

I notice your Run has no Stdout flag set so StdoutRead will have no stream to read from.

Link to comment
Share on other sites

Seems like quotes are needed. I will use some MsgBoxes to show what the changes are. It may help to look at the command string rather then running and wondering what is the issue is. Msgboxes and ConsoleWrites can help with debugging an issue.

See if this helps you and notice the difference between the Old Command that you have and the New Command that I modified from your Old Command.

GUICreate('test')
$File = GUICtrlCreateInput('Some file.exe', 0, 0)

MsgBox(0, 'Old Command', '"' & @ComSpec & '" /c "' & @TempDir & '\sod\bm.exe -o -d ' & @TempDir & '\sod\zi2.bms ' & GuiCtrlRead($File))

MsgBox(0, 'New Command', '"' & @ComSpec & '" /c "' & @TempDir & '\sod\bm.exe" -o -d "' & @TempDir & '\sod\zi2.bms" "' & GuiCtrlRead($File) & '"')

Exit

; this is perhaps the answer
Run('"' & @ComSpec & '" /c "' & @TempDir & '\sod\bm.exe" -o -d "' & @TempDir & '\sod\zi2.bms" "' & GuiCtrlRead($File) & '"', '', @SW_HIDE)

The Exit will end the script and so the Run will not happen so it is OK just as a test. :)

Link to comment
Share on other sites

  • Solution

The last one is with you setting a working directory. I do not see you making good use of it though it may have benefits if used to help with the command string. If you set the working directory of CMD to @TempDir then paths there can be relative to that path like you can do in a command prompt.

So a total of what could be used by setting the workingdir parameter to @TempDir

; Post #1
Run('"' & @ComSpec & '" /c bm.exe -d -o zi2.bms "' & @DesktopDir & '\ters.pak"', @TempDir, @SW_HIDE)
; Post #8
Run('"' & @ComSpec & '" /c sod\bm.exe -o -d sod\zi2.bms "' & GuiCtrlRead($File) & '"', @TempDir, @SW_HIDE)
; Post #10
Run('"' & @ComSpec & '" /c sod\bm.exe -o sodt\zi2.bms "' & GuiCtrlRead($File) & '" "' & @DesktopDir & '\P Ion"', @TempDir, @SW_HIDE)

If you still need help with those double quotes, then, perhaps this may help.

GUICreate('test')
$File = GUICtrlCreateInput('Some file.exe', 0, 0)

; Post #1
Local $tmp = @TempDir & '\stg'
Local $dtop = @DesktopDir

Global $command[7] = [ _
    @ComSpec, _
    '/c', _
    $tmp & '\sod\bm.exe', _
    '-d', _
    '-o', _
    $tmp & '\zi2.bms', _
    $dtop & '\ters.pak' _
]

$command = _ArrayToCmdLineString($command)
_Display($command)


; Post #8
Global $command[7] = [ _
    @ComSpec, _
    '/c', _
    @TempDir & '\sod\bm.exe', _
    '-o', _
    '-d', _
    @TempDir & '\sod\zi2.bms', _
    GuiCtrlRead($File) _
]

$command = _ArrayToCmdLineString($command)
_Display($command)


; Post #10
Global $command[7] = [ _
    @ComSpec, _
    '/c', _
    @TempDir & '\sod\bm.exe', _
    '-o', _
    @TempDir & '\sod\zi2.bms', _
    GuiCtrlRead($File), _
    @DesktopDir & '\P Ion' _
]

$command = _ArrayToCmdLineString($command)
_Display($command)


; Post #10 though with workingdir of @TempDir set in Run
; will do the array as one line for this test
Global $command[7] = [@ComSpec, '/c', 'sod\bm.exe', '-o', 'sod\zi2.bms', GuiCtrlRead($File), @DesktopDir & '\P Ion']

$command = _ArrayToCmdLineString($command)
_Display($command)

GUIDelete()

Exit

Func _ArrayToCmdLineString($aInput, $iLBound = 0)
    Local $1, $sOutput
    If Not IsArray($aInput) Then Return SetError(1, 0, '')
    For $1 = $iLBound To UBound($aInput) -1
        ; trim whitespace from both ends
        $aInput[$1] = StringStripWS($aInput[$1], 3)
        ; if double quotes are not on both ends and a space is found, then add double quotes
        If StringInStr($aInput[$1], ' ') And Not StringRegExp($aInput[$1], '\A".*"\Z') Then
            $sOutput &= '"' & $aInput[$1] & '" '
        Else
            $sOutput &= $aInput[$1] & ' '
        EndIf
    Next
    $sOutput = StringStripWS($sOutput, 3)
    If $sOutput == '' Then Return SetError(2, 0, '')
    Return $sOutput
EndFunc

Func _Display($message, $error = @error, $line = @ScriptLineNumber)
    ; display result of test
    If Not $error Then
        MsgBox(0, $line, $message)
    Else
        MsgBox(0x30, $line, '@error ' & $error)
    EndIf
EndFunc

The _ArrayToCmdLineString function will join the array elements into a string. It will put double quotes around elements that contain a space. The _Display function is just for easy showing of the result of each command. The lines that end with a space and then an underscore are continuation chars to indicate a line continued to the next line. If you have 6 elements in the array, then you insert 6 between the square brackets after the array name. You may noticed that I use $command for creation of the array and as the variable for the return from ArrayToCmdLineString. It is just reusing a variable since interest in the array is no more after the use of it. The $iLBound parameter is optional and is just useful if you want to start the joining of the command string from 1 or greater element of the array (default is 0).

Now the idea above may help as the command parameters are added to the array without quotes. Sometimes people like to break up a command into parts so it may help to make it easier to handle. You could also break it down as keeping it as a string though it may still be complicated for some. Like the string below.

$sCommand = _
    '"' & @ComSpec & '"' & _
    '/c' & _
    '"' & @TempDir & '\sod\bm.exe' & '"' & _
    '-o' & _ 
    '-d' & _ 
    '"' & @TempDir & '\sod\zi2.bms' & '"' & _ 
    '"' & GuiCtrlRead($File) & '"'

Choose what works for you. :)

Link to comment
Share on other sites

Chr(34) works for me.

Local $tmp = Chr(34) & @TempDir & Chr(34)
Local $dtop = Chr(34) & @DesktopDir & Chr(34)
MsgBox(4096,'', " /c " & $tmp & " bm.exe -d -o " & $tmp & " zi2.bms " & $dtop & " ters.pak")
Run(@ComSpec & " /c " & $tmp & " bm.exe -d -o " & $tmp & " zi2.bms " & $dtop & " ters.pak", "",@SW_HIDE)

So too can try:

$m = Chr(34) & " " & Chr(34)
Local $tmp = StringReplace(@TempDir, " ", $m)
Local $dtop = StringReplace(@DesktopDir, " ", $m)
MsgBox(4096,'', " /c " & $tmp & " bm.exe -d -o " & $tmp & " zi2.bms " & $dtop & " ters.pak ")
Run(@ComSpec & " /c " & $tmp & " bm.exe -d -o " & $tmp & " zi2.bms " & $dtop & " ters.pak", "",@SW_HIDE)
Edited by Belini
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...