使用.netcore调用windows服务器上安装的应用,使用cmd执行命令行实现业务,源代码如下:

string arguments = @" --convert-to pdf D:\bjredcross-base-mysql-filetransferservice\wwwroot\upload\oafilepdf\20260112\6c47958a26974e3f891a3761aad90377.doc --outdir D:\bjredcross-base-mysql-filetransferservice\wwwroot\upload\oafilepdf\20260112";

ProcessStartInfo startInfo = new ProcessStartInfo
{
    FileName = "D:\\LibreOffice\\program\\soffice.exe",
    Arguments = arguments,
    UseShellExecute = false,
    CreateNoWindow = true,
    RedirectStandardOutput = true
};

using (Process process = new Process())
{
    process.StartInfo = startInfo;
    process.Start();

    output = process.StandardOutput.ReadToEnd();

    // 等待进程结束
    process.WaitForExit();
}

源代码在运行环境可以直接运行,但部署到IIS后,需要对程序池进行设置。

需要在应用程序池中,设置应用的进程模型,添加登录用户标识。

posted on 2026-01-13 01:23  开源包容  阅读(5)  评论(0)    收藏  举报