ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd", "/c " + "MyExecutable.exe");
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
Process proc = new Process();
proc.StartInfo = procStartInfo;
proc.Start();
我的项目中有一个可执行文件,比如"我的可执行文件.exe"。运行此应用程序时,它将在执行此exe
的同一路径中创建日志文件。
如果我在命令提示符下运行此exe
,则没有问题。
但是如果我从 c# 代码运行 exe,它会在下面的代码中抛出错误"文件/访问错误"MyExecutable.exe
Open `sLogfile` For Output Access Write As `LogFileNumber`
其中sLogfile
是logfile
名称,LogFileNumber
是FreeFile
。
当前指南说不要将日志写入可执行文件目录。这可能是 Windows 强制实施此指南。改为写入用户的AppData
目录。