I’m a hobby C# programmer and I’m making an interface for a CLI tool called setMACE. This is a snippet of the code that I’m using:
if (!File.Exists(batpath))
{
using (FileStream fs = File.Create(batpath))
{
fs.Close();
}
using (StreamWriter sw = new StreamWriter(batpath))
{
int outfile = r.Next(5);
sw.WriteLine("cd " + Application.StartupPath);
sw.WriteLine(exe + " " + "\"" + ofd.FileName + "\"" + " -d " + " >>logfile.txt");
}
Process proc = Process.Start(batpath);
And this will make the following .BAT:
cd C:\Users\Steve Jobs\Pictures\SetMACE_v1006
setMACE_x64.exe "C:\Users\Steve Jobs\Documents\avast.cap" -d >>logfile.txt
This works when I execute this .BAT in the CMD but when I let the app run it, it spawns a new window with the program and ignores the >output.txt
I’m sorry if this is a no-brainer, but I can’t find anything on it online.
It seems that you’re spawning a second instance of cmd, via start, which may not be starting in the same directory to which you’re cd’ing
Why does your batch file have “start cmd”, why don’t you just run setMACE_x64.exe directly?
I.e. your batch file would then be: