Sign in to follow this  
Followers 0
Qousio

Shellexucute'ing a bat file

7 posts in this topic

#1 ·  Posted (edited)

Hello!

I want to ShellExecute a .bat file. I have read the FAQ and help file on Shellexecute and Run functions, but that didnt really help...

Usually this is how I run the .bat file:

Command: %comspec% /k ""F:\Prog\VC2008\VC\vcvarsall.bat"" x86

I have tried this in autoit:

ShellExecute("vcvarsall.bat", @ComSpec & " /k", "F:\Prog\VC2008\VC\")

I have also tried several variations with parameters and the verb. But the .bat file instantly closes after launching.

How do I prevent it from closing?

Edited by Qousio

Share this post


Link to post
Share on other sites



Hello!

I want to ShellExecute a .bat file. I have read the FAQ and help file on Shellexecute and Run functions, but that didnt really help...

Usually this is how I run the .bat file:

Command: %comspec% /k ""F:\Prog\VC2008\VC\vcvarsall.bat"" x86

I have tried this in autoit:

ShellExecute("vcvarsall.bat", @ComSpec & " /k", "F:\Prog\VC2008\VC\")

I have also tried several variations with parameters and the verb. But the .bat file instantly closes after launching.

How do I prevent it from closing?

Does that bat have "pause" in it?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hello!

I want to ShellExecute a .bat file. I have read the FAQ and help file on Shellexecute and Run functions, but that didnt really help...

Usually this is how I run the .bat file:

Command: %comspec% /k ""F:\Prog\VC2008\VC\vcvarsall.bat"" x86

I have tried this in autoit:

ShellExecute("vcvarsall.bat", @ComSpec & " /k", "F:\Prog\VC2008\VC\")

I have also tried several variations with parameters and the verb. But the .bat file instantly closes after launching.

How do I prevent it from closing?

Console closed after BAT file has finished its work. To prevent this, do one of the following.

  • ShellExecute("cmd.exe", "/k vcvarsall.bat " & @ComSpec & " /k", "F:\Prog\VC2008\VC\")
  • Write the word PAUSE at the end of your BAT file.
Edited by Yashied

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I prefer RUN because of the "standard_i/o_flag" that give you the option to read output from the batch...

$batch = Run(@ComSpec & " /c vcvarsall.bat ",  "F:\Prog\VC2008\VC\", @SW_SHOW)
while ProcessExists($batch)
    consolewrite("batch still running"&@CRLF)
    WEnd

My example assumes that the batch starts and ends

Like this one:

@echo off
echo Hello World
xcopy folder1\*.* folder2\*.* /q /r /s /y
pause

Untill the process exists you can see some console output. As soon as you press a key in the new window of the batch, the script continues.

The stdout is not part of the example.

I'm not stating that RUNis better or not than ShellExecute. I just do it this way...

Edited by Tankbuster

Share this post


Link to post
Share on other sites

Thanks for the info Yashied and Tankbuster, it works perfectly now.

Share this post


Link to post
Share on other sites

Sorry for reopening this topic but i have kind of the same issue.

when i use the command below a cmd will open and the prompt is "C:UsersmyuserAppDataLocalmyprog>" but nothing else happens.

What it should do is to run the file "rename.bat" and hand over the parameter "$ipath" & "$ifilename" & "$EnvVar".

BTW full path to "rename.bat" is "C:UsersmyuserAppDataLocalmyprogrename.bat"

Local $ipath = @ScriptFullPath
Local $ifilename = @ScriptName
Local $EnvVar = EnvGet("USERPROFILE") & "\AppData\Local\myprog"
ShellExecute ("cmd.exe", "rename.bat" & " " & Chr(34) & $ipath & Chr(34) & " " & Chr(34) & $ifilename & Chr(34) & " " & Chr(34) & $EnvVar & Chr(34), $EnvVar & "\")

 

Share this post


Link to post
Share on other sites

Hey I found the mistake, this is how it works.

ShellExecute ($EnvVar & "\rename.bat", Chr(34) & $ipath & Chr(34) & " " & Chr(34) & $ifilename & Chr(34) & " " & Chr(34) & $EnvVar & Chr(34))

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