Jump to content

Trouble passing arguments


Recommended Posts

Hi All,

I'm **brand** new to AutoIt, but spent the whole weekend messing with it - and having fun! I'm coming over from another language (Lua) and see the similarities and differences. Maybe someone can shed some light on this problem.

I am launching a compiled AutoIt script from within another program. This AutoIt script is designed to start another program and then launch another AutoIt to watch the window of the launched program. If the window closes, all the files in it's temp folder are to be deleted.

My problem is passing the variables as arguments to the second AutoIt. Attached is the code (I've cleaned it out for simplicity sake of posting)

if $Cmdline[0] <>2 Then
    Exit(10)
else 
    $path=$Cmdline[1]
    $title=$Cmdline[2]
EndIf

Run($path & "\program.exe",$path,@SW_MAXIMIZE)
if @error Then
    Exit
EndIf

WinWait($title)
$nRunPid=WinGetProcess($title)
$nRunHandle = WinGetHandle($title, "")
$sRunHandle = String($nRunHandle)

$bIsLive=False
MaxWin()

func MaxWin()
    $state=WinGetState(HWnd($sRunHandle))
    while not BitAND($state, 32)
        sleep(100)
    WEnd
    
    if BitAND($state, 32) = true Then
    $bIsLive=True
        EndIf
    EndFunc
    
if $bIsLive = True Then
$Args='"'&$path&'"' &' ' &'"'&$nRunPid&'"'
;the mess with the $Args above is because the path may contain spaces
ConsoleWrite($nRunPid & @CRLF)
Run("D:\\2.exe ", $Args, @SW_HIDE)
EndIf
Exit

The second AutoIt script called is "2.exe" in the above example. Code:

if $Cmdline[0] <>2 Then
    Exit(10)
else 
    $path=$Cmdline[1]
    $nRunPid=$Cmdline[2]
    EndIf

ProcessWaitClose($nRunPid)
FileDelete($path&"\*.*")

Exit

The trouble being that 2.exe won't run when the arguments are passed. If I run in the console and grab the PID of the launched window, I can enter this into the "Parameters" in the console and 2.exe runs fine.

Maybe I'm missing something, but I come for the guidance of the gurus...

Thanks for any suggestions,

Dean

Link to comment
Share on other sites

Hi MadDogDean,

welcome to the AutoIt Forum!

If you take a look at the Help for the "Run" command, you may find, that the second argument is not a parameter to the exe but the workingdir. Try using Run($path & "\program.exe " & $path, @ScriptDir, @SW_MAXIMIZE)

Regards,

Hannes

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
Link to comment
Share on other sites

Hi & welcome!

the second parameter of Run ist the WorkingDir. But that is not what you want to set, right?

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Thanks to you both for the welcome and the help.

I know it should be quite obvious. I was formatting the "Run" like I do in the other program...

The first run for "program.exe" works fine, but the second one is still giving me troubles. I changed it and tried:

if $bIsLive = True Then
$Args='"'&$path&'"' &' ' &'"'&$nRunPid&'"'
;the mess with the $Args above is because the path may contain spaces
ConsoleWrite($nRunPid & @CRLF)
Run("D:\\2.exe " & $Args, @ScriptDir, @SW_HIDE)

but still no results :)

Any other thoughts??

Thanks,

Dean

Link to comment
Share on other sites

Hmmmm... maybe I'm missing something.

I think the problem might stem from "2.exe" getting the parameters, but something doesn't mesh once inside.

Rather than using the PID, I modified it using the Window title instead of the PID and it seems to work fine. The problem is that in my application it is possible for more than one window to have the same name, so 'Window title" isn't really an option, I need to use the PID.

Well, back to it :)

Ideas are still welcome!

Cheers,

Dean

Edited by MadDogDean
Link to comment
Share on other sites

Everything you want is possible. What's the problem?

Besides, you can also use Shellexecute instead of Run.

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

@Triblade,

Thanks for the link, that was an interesting read. I am nowhere (yet) near that level. Somebody in the thread refers to their speed changing from pedal power to rocket power - heck, I'm still trying to attach the pedals :)

Gives me some thoughts though. Thanks.

@Xenobiologist

I tried using ShellExe but with this app I'm trying to adapt it didn't startup everytime ?? The Run works fine for now. I've figured out about the problem passing arguments and now it works fine as well.

My only other problem is that my AutoIt compiled exe (App1.exe) launches another AutoIt compiled exe (App2.exe) to WinWaitClose based on a Window title, but for some reason if App2.exe is still running, it won't run a second instance of it?? Don't know why, but the help I've gotten from a couple of threads has given me lots of things to look at and try.

I think rather than using the Windows title (because my app might have doubles names), I am going to get the PID of App1.exe, find it's WinHandle and watch the process based on WinHandle.

Again thanks to all for your help.

Cheers,

Dean

Link to comment
Share on other sites

Hi,

there are many possibilities.

You can check with ProcessExists whether your app1 is running.

You can change the title of a running application or you can even let your script check the processes currently running and name the titles of your window dependent on the amount of processes.

You could ProcessClose all processes with the name of your app2 before you start it again.

You could use _Singleton to be sure there is only one instance running at a time.

...

All you need is possible :)

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

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...