我無法通過在Windows上呼叫快捷方式將標準輸出重定向到檔案中。
它直接作業 "exe.exe 1 2 1 4 5 6 7 >> log.txt",日志檔案被成功生成。
我認為">> "符號在使用快捷方式.lnk時被當作一個引數,因此它沒有生成log.txt
。我怎樣才能正確地啟動命令或修改程式以達到我想要的效果?
這里是我的代碼:
static void Main(string[] args)?
{
string acc = ""。
string pass = "";
string EmailEnabled = "";
string smtpServer = "";
string sender = "";
string smtpAuth = "";
string receiver = "";
if (args.Length == 7)
{
acc = args[0] 。
pass = args[1]。
EmailEnabled = args[2]。
smtpServer = args[3]。
sender = args[4];
smtpAuth = args[5]。
receiver = args[6]。
}
else if (args[2] == "0"/span>)
{
acc = args[0] 。
pass = args[1]。
EmailEnabled = args[2]。
}
else; }
{
Console.WriteLine("命令列引數有誤")。
return;
}
}
螢屏截圖:
。uj5u.com熱心網友回復:
我相信這個問題與Windows有關,而不是與C#有關。 所以要重定向快捷方式
@Flydog57的評論
cmd /c "file_shortcut.lnk"/span> bla bla bla >out.txt
在C#上。
你可以制作第8個引數輸出檔案并重定向標準輸出
以下是這個。
console.setout
可能是這樣的:
using (var writer = args.Length>7? new StreamWriter(args[7]) : new StreamWriter(Console.OpenStandardOutput() ) )
{
Console.SetOut(writer)。
//所有代碼在里面。
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/324699.html
標籤:
