Jump to content

Shellexucute'ing a bat file


Recommended Posts

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
Link to comment
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?
Link to comment
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?

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 4 years later...

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 & "\")

 

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