Sign in to follow this  
Followers 0
Znuffie

RunWait() works in a 2-line script but not in a more complex script

7 posts in this topic

#1 ·  Posted (edited)

Hello,

I have the following codes:

$ImageFile = "T:\work\wave.png";
$sStatus = RunWait(".\tools\convert.exe -background #181818 " & $ImageFile & " -resize 1280x1280^> -gravity center -extent 1280x720 temp/background.png", "");

This works perfectly like this.

Now in my main script which I'm working on, I can't figure out why it's not working:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <constants.au3>
#Region ### START Koda GUI section ### Form=t:\work\stics\form1.kxf
Global $Stics = GUICreate("Stics", 403, 555, 198, 128, -1, BitOR($WS_EX_ACCEPTFILES,$WS_EX_WINDOWEDGE))
GUISetIcon("T:\Work\Stics\Icon.ico", -1)
Global $StatusBar1 = _GUICtrlStatusBar_Create($Stics)
Global $StatusBar1_PartsWidth[1] = [-1]
_GUICtrlStatusBar_SetParts($StatusBar1, $StatusBar1_PartsWidth)
_GUICtrlStatusBar_SetText($StatusBar1, "Ready!", 0)
Global $ImageGroup = GUICtrlCreateGroup("Background Image", 8, 8, 385, 97)
Global $PathImg = GUICtrlCreateInput("", 16, 32, 289, 21)
Global $BrowseImg = GUICtrlCreateButton("Browse...", 312, 32, 75, 21)
Global $LabelImg1 = GUICtrlCreateLabel("The image should be a PNG of 1280x720 pixels", 16, 58, 229, 17)
Global $LabelImg2 = GUICtrlCreateLabel("Smaller images will be padded. Larger images will be shrinked.", 16, 78, 295, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $Mp3Group = GUICtrlCreateGroup("Song", 8, 110, 385, 97)
Global $PathMp3 = GUICtrlCreateInput("", 16, 134, 289, 21)
Global $BrowseMp3 = GUICtrlCreateButton("Browse...", 312, 134, 75, 21)
Global $LabelMp31 = GUICtrlCreateLabel("Should be an MP3, preferably at 320kbps", 16, 160, 200, 17)
Global $LabelMp32 = GUICtrlCreateLabel("Other file types/sources will be converted to 320kbps MP3", 16, 180, 280, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $TextGroup = GUICtrlCreateGroup("Text && Info", 8, 216, 385, 113)
Global $InputTxt = GUICtrlCreateInput("InputTxt", 16, 240, 369, 21)
Global $LabelTxt1 = GUICtrlCreateLabel("This is the text that will be written in the middle of the video.", 16, 266, 283, 17)
Global $LabelTxt2 = GUICtrlCreateLabel("In most cases this will be auto-generated from Artist - Track name.", 16, 286, 313, 17)
Global $LabelTxt3 = GUICtrlCreateLabel("You can change the text here if you don't like it", 16, 306, 226, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $TypeGroup = GUICtrlCreateGroup("Video Type", 8, 336, 385, 81)
Global $Spectrowave = GUICtrlCreateRadio("Spectrowave", 16, 360, 169, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
Global $Waveform = GUICtrlCreateRadio("Slider over Waveform", 16, 384, 169, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $DebugGroup = GUICtrlCreateGroup("DEBUG", 8, 424, 385, 73)
Global $DebugVideo = GUICtrlCreateLabel("VIDEO:", 16, 448, 369, 17)
Global $DebugAudio = GUICtrlCreateLabel("AUDIO:", 16, 472, 41, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $ConvertMe = GUICtrlCreateButton("Convert Me!", 312, 504, 80, 25)
Global $Progress = GUICtrlCreateProgress(8, 508, 302, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

DirCreate("temp");

Func PickFile($type)
    if $type = "img" Then
        $sMessage = "Please select the image you would like to use as a background";
        $sFTypes = "Images (*.jpg;*.png;*.bmp;)";
    ElseIf $type = "audio" Then
        $sMessage = "Please select the song you would liek to use as a background";
        $sFTypes = "Audio Files (*.mp3;*.mp4;*.m4a;*.wav;*.ogg;*.flac;)";
    EndIf

    ; Display an open dialog to select a list of file(s).
    Local $sFileOpenDialog = FileOpenDialog($sMessage, "", $sFTypes, $FD_FILEMUSTEXIST)
    If @error Then
        ; Display the error message.
        MsgBox($MB_SYSTEMMODAL, "", "No file(s) were selected.")
        return @error;
    Else
        ; Replace instances of "|" with @CRLF in the string returned by FileOpenDialog.
        $sFileOpenDialog = StringReplace($sFileOpenDialog, "|", @CRLF)

        ; Display the list of selected files.
        return $sFileOpenDialog;
    EndIf
EndFunc   ;==>Example

Func ProcessImage($ImageFile)
    if FileExists($ImageFile) Then
        $ImageFile = "T:\work\wave.png";
        $sStatus = RunWait(".\tools\convert.exe -background #181818 " & $ImageFile & " -resize 1280x1280^> -gravity center -extent 1280x720 temp/background.png", "");
        ConsoleWrite(".\tools\convert.exe -background #181818 " & $ImageFile & " -resize 1280x1280^> -gravity center -extent 1280x720 temp/background.png");
        ConsoleWrite(@CRLF & "RunWait Status: " & $sStatus & ", @Error = " & @Error)
    Else
        MsgBox($MB_SYSTEMMODAL, "Error!", "Couldn't convert the image. Something is wrong! :(")
    EndIf
EndFunc

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Stics
        Case $Stics
        Case $Stics
        Case $Stics
        Case $PathImg
        Case $BrowseImg
            GUICtrlSetData($PathImg, PickFile("img"));
            ProcessImage(GUICtrlRead($PathImg));
        Case $LabelImg1
        Case $LabelImg2
        Case $PathMp3
        Case $BrowseMp3
            GUICtrlSetData($PathMp3, PickFile("audio"));
        Case $LabelMp31
        Case $LabelMp32
        Case $InputTxt
        Case $LabelTxt1
        Case $LabelTxt2
        Case $LabelTxt3
        Case $Spectrowave
        Case $Waveform
        Case $DebugVideo
        Case $DebugAudio
        Case $ConvertMe
    EndSwitch
WEnd

Could someone explain me why this doesn't work? I always get @error set to 1 and that's it :-(

Edited by Znuffie

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

tools\convert.exe -background #181818 T:\Work\wallpaper-1974515.jpg -resize 1280x1280^> -gravity center -extent 1280x720 temp\background.png
RunWait Status: 0, @Error = 0

Edited by Znuffie

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Well, Based on my quick skim of your code, It appears that you're calling the ProcessImage function with the ImageFile parameter. Which is not declared prior to calling that function, From what I could see. I would say that's whats causing the error. If it is declared somewhere and, I didn't notice it sorry for that :P

Edit: Also you're line of code:

if FileExists($ImageFile) Then

Will always fail too because, Like your function it's checking for a yet-to-be-declared variable.

Edited by BlackDawn187

Share this post


Link to post
Share on other sites

 FileOpenDialog changes the CWD


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Oh, thank you! That was it...

I really wanted to use relative paths. Wouldn't have figured it out that it changed the CWD!

Share this post


Link to post
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
Sign in to follow this  
Followers 0