This commit is contained in:
c
2023-07-29 21:59:37 +08:00
parent ce27f1d693
commit 15c0aa1c5c
12 changed files with 367 additions and 65 deletions

View File

@@ -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,