
就這點東西,用控制臺或者其他WinForm程式都能用,但是搬到我的專案里就不管用了,哪位大佬知道啥情況?
uj5u.com熱心網友回復:
cmd.startInfo.fileName你這裡能執行嗎,,還有你的oracle的服務名是一樣的嗎uj5u.com熱心網友回復:
這個是可以執行的,orcle里面的exp.exe檔案。在別的winform或者控制臺都可以執行!uj5u.com熱心網友回復:
是的 這個在cmd里是可以直接運行成功的!
uj5u.com熱心網友回復:
直接把你的exp命令寫到dat里面 程式執行dat檔案 簡單多了uj5u.com熱心網友回復:
那你打斷點調試,看看其他可以運行的,如在控制臺調試在哪裡的參數,你的項目又是什麼參數
uj5u.com熱心網友回復:
你試下這個函式
/// <summary>
/// 運行cmd命令
/// </summary>
/// <param name="dosCommand">cmd 命令列</param>
/// <param name="milliseconds">0</param>
/// <returns></returns>
public static string RunCommand(string dosCommand, int milliseconds)
{
string output = ""; //輸出字串
if (dosCommand != null && dosCommand != "")
{
Process process = new Process(); //創建行程物件
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "cmd.exe"; //設定需要執行的命令
startInfo.Arguments = "/C " + dosCommand; //設定引數,其中的“/C”表示執行完命令后馬上退出
startInfo.UseShellExecute = false; //不使用系統外殼程式啟動
startInfo.RedirectStandardInput = false; //不重定向輸入
startInfo.RedirectStandardOutput = true; //重定向輸出
startInfo.RedirectStandardError = true;
startInfo.CreateNoWindow = true; //不創建視窗
process.StartInfo = startInfo;
try
{
if (process.Start()) //開始行程
{
if (milliseconds == 0)
process.WaitForExit(); //這里無限等待行程結束
else
process.WaitForExit(milliseconds); //當超過這個毫秒后,不管執行結果如何,都不再執行這個DOS命令
output = process.StandardOutput.ReadToEnd();//讀取行程的輸出
if (output == "") //運行失敗回傳失敗原因
output = process.StandardError.ReadToEnd();
}
}
catch
{
}
finally
{
if (process != null)
process.Close();
}
}
return output;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/141497.html
標籤:C#
上一篇:如何用C#改音頻檔案的采樣率?
下一篇:CSDN的產品應該辭掉了。。。
