MStest fails when called as a batch file from Coded ui - winforms

I have a batch file which is used to run mstest.Clicking on the batch file executes the file just fine. However when the same file is called from a win form application, mstest fails. This behaviour seems quirky.Could anyone provide any reasons for this.
I have used the following code to call it :
Process myProcess = new Process();
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(#"D:\CodedUI\CommonAutomationFramework\Driver_batch.bat");
myProcessStartInfo.UseShellExecute = false;
myProcess.StartInfo = myProcessStartInfo;
myProcess.Start();

What exactly is failing? The test(s) or MSTest itself?
Anyway a batch file executes commands on the command line interpreter (cmd).
In the process you're starting, maybe you should start 'cmd.exe' instead. Read the contents of the batch file and pass them a an addiction to 'cmd.exe'
Like this:
ProcessStartInfo processInfo;
Process process;
processInfo = new ProcessStartInfo("cmd.exe", "/c " + command);
(...)
Where your 'command' here is the text in the batch file.
You could also try this:
System.Diagnostics.Process.Start(#"D:\CodedUI\CommonAutomationFramework\Driver_batch.bat");

Related

Why can't I use the command prompt after running a batch file on it?

So I have a batch file that simply runs an exe file. I want to be able to open the command prompt, run the batch file, then... I want to type another command in the command prompt.
here is the code that is in the batch file called "sublime.bat":
"C:\Sublime Text 3\sublime_text.exe"
I open cmd in the directory with my bat file and I type:
"sublime.bat"
It works by opening sublime text but the cmd cursor starts flashing and I can no longer type anything until I close sublime text.
I want to be able to open sublime text and type commands out while still having sublime text open. Please help, thanks.
Command prompt doesn't execute a further line, while a command is on execution. It executes commands serially, not parallelly. So if you want a command to be executed cmd should return from executing previous one.
Here, in "sublime.bat" you have called a batch file which contains a command of executing another program. So, cmd waits for the result of executing the bat file and thus stuck there.
You can use start "/k" "C:\Sublime Text 3\sublime_text.exe" in your "sublime.bat". This holds only the start command and cmd gets free after starting the file.

Calling batch file from F-Sharp

Is there any way i can call a batch-file from within my F# program? My batch file is called eso.bat, and is to download the html content of a website. The file works, but it would be nice if it could be done automatically by the program itself.
The simple way is:
open System.Diagnostics
Process.Start "..\eso.bat"
if you need to pass parameteres or specify the starting directory then:
open System.Diagnostics
let procStart = ProcessStartInfo("eso.bat", "params", WorkingDirectory = "..")
let proc = new Process(StartInfo = procStart)
proc.Start()

Running cmd command from vb.net issue

I am trying to run the following code in a click event. However because it executes the command in the cmd shell, I don't know why it wont run. What I can do is open cmd.exe as Administrator by commenting out the Arguments. As well as stick these arguments in a .bat file, then running from process.start.
However, why I cant run the shell with the arguments? I'd prefer this method over putting the arguments in a .bat file.
Dim process As New System.Diagnostics.Process()
Dim startInfo As New System.Diagnostics.ProcessStartInfo()
' startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden
startInfo.FileName = "cmd.exe"
If System.Environment.OSVersion.Version.Major >= 6 Then ' Windows Vista or higher
startInfo.Verb = "runas"
Else
' No need to prompt to run as admin
End If
startInfo.Arguments = "/C bcdedit /set {current} safeboot network"
process.StartInfo = startInfo
process.Start()
Figured it out. I had to copy bcdedit.exe to my project. I had thought that calling cmd.exe would go to the location bcdedit.exe was located.

making a batch file run hidden/minimized without modifying the shortcut

I'm writing an application in VB.net that creates and calls batch files. I'd like these batch files to run hidden, but since there will be no shortcuts for the files, I would need to set this in the batch code itself. How would I do this?
the vbs script in the link looks good, but if you are calling the batch files from the VB app then you can run the batch files hidden:
Dim p As New Process()
p.StartInfo.FileName = "cmd.exe"
p.StartInfo.Arguments = "/C mybatchfile.bat"
p.StartInfo.CreateNoWindow = True
p.StartInfo.UseShellExecute = False
p.Start()
p.WaitForExit();// this line waits for the batch to finish, remove if you want to start the batch and continue your app while it runs.
Martyn

How do I call a batch file from an MSI

I have an msi installer that needs to call a few batch files to finish the install procedure. The batch file copies extra files from the installer to a few directories and then modifies permissions on several of those directories. We want to continue using the batch files because there is not a lot of time left in our development schedule. I am not using WIX.
If possible I would like to capture the output of the batch as it goes and write it to a log file.
Found bellow is the code I am using to try to run the batch file from a custom action. It opens a cmd window, runs for a while but never seems to finish. If I run the same batch files directly from the command prompt they work.
//Set the environment to the directory containing the bat files
ProcessStartInfo info = new ProcessStartInfo(batch);
info.WindowStyle = ProcessWindowStyle.Hidden;
info.UseShellExecute = false;
info.RedirectStandardError = true;
info.RedirectStandardOutput = true;
if (!string.IsNullOrEmpty(argument))
info.Arguments = argument;
Process process = new Process();
process.StartInfo = info;
process.Start();
// Capture the standard error and standard output
What am I doing wrong?
I believe you'll need to create a custom action. See this question.
Many anti-virus programs may stop execution of .BAT files during an installation process, you should really be doing this using standard Windows Installer functionality or as a C++ Custom Action

Resources