1
This commit is contained in:
@@ -11,16 +11,17 @@ namespace NetPanel.Bl
|
||||
public class ExecuteBl
|
||||
{
|
||||
|
||||
public static string Exec(string command)
|
||||
|
||||
public static string Exec(string fileName,string command)
|
||||
{
|
||||
|
||||
if (OperatingSystem.IsWindows()) // 检查当前操作系统是否为 Windows
|
||||
{
|
||||
return ExecuteCommandOnWindows(command);
|
||||
return ExecuteCommandOnWindows(fileName, command);
|
||||
}
|
||||
else if (OperatingSystem.IsLinux()) // 检查当前操作系统是否为 Linux
|
||||
{
|
||||
return ExecuteCommandOnLinux(command);
|
||||
return ExecuteCommandOnLinux(fileName, command);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -28,20 +29,21 @@ namespace NetPanel.Bl
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// win 执行命令
|
||||
/// </summary>
|
||||
/// <param name="command"></param>
|
||||
/// <returns></returns>
|
||||
private static string ExecuteCommandOnWindows(string command)
|
||||
private static string ExecuteCommandOnWindows(string fileName ,string command)
|
||||
{
|
||||
|
||||
using var process = new Process
|
||||
{
|
||||
StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "cmd.exe",
|
||||
Arguments = "/C " + command,
|
||||
FileName = fileName,
|
||||
Arguments = command,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
//StandardErrorEncoding = Encoding.UTF8,
|
||||
@@ -65,15 +67,15 @@ namespace NetPanel.Bl
|
||||
/// linux 执行命令
|
||||
/// </summary>
|
||||
/// <param name="command"></param>
|
||||
private static string ExecuteCommandOnLinux(string command)
|
||||
private static string ExecuteCommandOnLinux(string fileName ,string command)
|
||||
{
|
||||
|
||||
using var process = new Process
|
||||
{
|
||||
StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "/bin/bash",
|
||||
Arguments = "-c \"" + command + "\"",
|
||||
FileName = fileName,
|
||||
Arguments = command,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
//StandardErrorEncoding = Encoding.UTF8,
|
||||
|
||||
Reference in New Issue
Block a user