ASP.NET:执行外部可执行文件不起作用

发布于 2024-08-04 10:18:01 字数 2583 浏览 0 评论 0原文

我需要以下代码的帮助。 我尝试将 AutoCAD 文件从 dwg 格式转换为 dwf 格式。 然后,使用 java 小程序在客户端计算机上下载并打开 dwf 文件。

用于在命令行上转换 dwg 文件的命令是: C:\inetpub\wwwroot\COR-Basic\cadviewer\converter\ax2008.exe -i="C:\inetpub\wwwroot\test\container\DU38_EG00_070116.dwg" -o="C:\inetpub\wwwroot\COR- Basic\cadviewer\files\DU38_EG00_070116.dwf" -f=dwf -model -text

当我在 cmd.exe 中输入命令文本时,此功能有效。

但是当我从我的 asp.net 应用程序调用它时,它只启动该进程,但该进程永远不会结束...

我尝试添加一个额外的用户,已授予该用户完全权限,以及 wwwroot 的完全权限,但它还是不行。

任何人都知道我做错了什么,或者我可以如何以其他方式做到这一点?

  If System.IO.File.Exists(strDWGlocation) Then
        Dim psiProcessSettings As Diagnostics.ProcessStartInfo = New Diagnostics.ProcessStartInfo
        psiProcessSettings.FileName = strApplicationPath
        psiProcessSettings.Arguments = " -i=""" & strDWGlocation & """ -o=""" & strOutputLocation & """ -f=dwf -model -text"
        'ST-LAPTOP\converter
        psiProcessSettings.UserName = "converter"
        psiProcessSettings.Password = secureString

        'StefanSteiger.Debug.MsgBox("Input location:" + strDWGlocation)
        'StefanSteiger.Debug.MsgBox("Output location:" + strOutputLocation)
        Response.Write("<h1>Argument1: " + psiProcessSettings.Arguments + "</h1>")
        Response.Write("<h1>Pfad1: " + psiProcessSettings.FileName + "</h1>")


        'psiProcessSettings.RedirectStandardInput = True
        psiProcessSettings.RedirectStandardError = True
        psiProcessSettings.RedirectStandardOutput = True 'Redirect output so we can read it.
        psiProcessSettings.UseShellExecute = False 'To redirect, we must not use shell execute.
        'psiProcessSettings.CreateNoWindow = True ' don't create a window
        Dim pConverterProcess As Diagnostics.Process = New Diagnostics.Process
        pConverterProcess = Diagnostics.Process.Start(psiProcessSettings) 'Create the process.
        pConverterProcess.Start() 'Execute the process.
        'Response.Write("<h1>" + Replace(pConverterProcess.StandardOutput.ReadToEnd(), vbCrLf, "<BR />") + "</h1>") 'Send whatever was returned through the output to the client. 

        'pConverterProcess.CancelOutputRead()
        'pConverterProcess.CancelErrorRead()
        'pConverterProcess.StandardInput.Close()
        'Wait for the process to end.
        'pConverterProcess.WaitForExit()
        pConverterProcess.Close()
        'Dim iExitCode As Integer = pConverterProcess.ExitCode()
        pConverterProcess.Dispose()
    Else
        MyNamespace.Debug.MsgBox("No such file.")
    End If

I need help with the code below.
I try to convert a AutoCAD file from the format dwg to the format dwf.
Then, the dwf file is downloaded and opened on the client computer using a java applet.

The command used to convert the dwg file on the command-line is:
C:\inetpub\wwwroot\COR-Basic\cadviewer\converter\ax2008.exe -i="C:\inetpub\wwwroot\test\container\DU38_EG00_070116.dwg" -o="C:\inetpub\wwwroot\COR-Basic\cadviewer\files\DU38_EG00_070116.dwf" -f=dwf -model -text

this works when I enter the command text in cmd.exe.

But when I call it from my asp.net application, it only starts the process, but the process never ends...

I've tried adding an additional user, have given this user full permission, and full permissions on wwwroot, but it still doesn't work.

Anybody knows what I'm doing wrong, or how I could do it in another way?

  If System.IO.File.Exists(strDWGlocation) Then
        Dim psiProcessSettings As Diagnostics.ProcessStartInfo = New Diagnostics.ProcessStartInfo
        psiProcessSettings.FileName = strApplicationPath
        psiProcessSettings.Arguments = " -i=""" & strDWGlocation & """ -o=""" & strOutputLocation & """ -f=dwf -model -text"
        'ST-LAPTOP\converter
        psiProcessSettings.UserName = "converter"
        psiProcessSettings.Password = secureString

        'StefanSteiger.Debug.MsgBox("Input location:" + strDWGlocation)
        'StefanSteiger.Debug.MsgBox("Output location:" + strOutputLocation)
        Response.Write("<h1>Argument1: " + psiProcessSettings.Arguments + "</h1>")
        Response.Write("<h1>Pfad1: " + psiProcessSettings.FileName + "</h1>")


        'psiProcessSettings.RedirectStandardInput = True
        psiProcessSettings.RedirectStandardError = True
        psiProcessSettings.RedirectStandardOutput = True 'Redirect output so we can read it.
        psiProcessSettings.UseShellExecute = False 'To redirect, we must not use shell execute.
        'psiProcessSettings.CreateNoWindow = True ' don't create a window
        Dim pConverterProcess As Diagnostics.Process = New Diagnostics.Process
        pConverterProcess = Diagnostics.Process.Start(psiProcessSettings) 'Create the process.
        pConverterProcess.Start() 'Execute the process.
        'Response.Write("<h1>" + Replace(pConverterProcess.StandardOutput.ReadToEnd(), vbCrLf, "<BR />") + "</h1>") 'Send whatever was returned through the output to the client. 

        'pConverterProcess.CancelOutputRead()
        'pConverterProcess.CancelErrorRead()
        'pConverterProcess.StandardInput.Close()
        'Wait for the process to end.
        'pConverterProcess.WaitForExit()
        pConverterProcess.Close()
        'Dim iExitCode As Integer = pConverterProcess.ExitCode()
        pConverterProcess.Dispose()
    Else
        MyNamespace.Debug.MsgBox("No such file.")
    End If

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

海未深 2024-08-11 10:18:01

这是我的代码,做了类似的事情,而且它有效!

            process.StartInfo.FileName = toolFilePath;
            process.StartInfo.Arguments = parameters;

            process.StartInfo.UseShellExecute = false; // needs to be false in order to redirect output
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError = true;
            process.StartInfo.RedirectStandardInput = true; // redirect all 3, as it should be all 3 or none
            process.StartInfo.WorkingDirectory = Path.GetDirectoryName(toolFilePath);

            process.StartInfo.Domain = domain;
            process.StartInfo.UserName = userName;
            process.StartInfo.Password = decryptedPassword;

            process.Start();

            output = process.StandardOutput.ReadToEnd(); // read the output here...

            process.WaitForExit(); // ...then wait for exit, as after exit, it can't read the output

            returnCode = process.ExitCode;

            process.Close(); // once we have read the exit code, can close the process

This is my code that does a similar thing, and it works!

            process.StartInfo.FileName = toolFilePath;
            process.StartInfo.Arguments = parameters;

            process.StartInfo.UseShellExecute = false; // needs to be false in order to redirect output
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError = true;
            process.StartInfo.RedirectStandardInput = true; // redirect all 3, as it should be all 3 or none
            process.StartInfo.WorkingDirectory = Path.GetDirectoryName(toolFilePath);

            process.StartInfo.Domain = domain;
            process.StartInfo.UserName = userName;
            process.StartInfo.Password = decryptedPassword;

            process.Start();

            output = process.StandardOutput.ReadToEnd(); // read the output here...

            process.WaitForExit(); // ...then wait for exit, as after exit, it can't read the output

            returnCode = process.ExitCode;

            process.Close(); // once we have read the exit code, can close the process
丿*梦醉红颜 2024-08-11 10:18:01

为什么要注释掉 WaitForExit() ?

您也可以尝试将 EnableRaisingEvents 设置为 true。

根据我的经验,在读取标准输出时,Process 类很难使用,请尝试删除任何尝试重定向和读取输出的代码

Why have you commented out the WaitForExit()?

You could try setting EnableRaisingEvents to true as well.

In my experience, the Process class is quite difficult to work with when reading the standard output, try removing any code that attempts to redirect and read output

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文