views:

449

answers:

2

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
A: 

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

Fiona Holder
I've commented it out because I thought maybe it's the error source.But it's not.I've already tried omitting redirection, but to no avail...I'll try using enableraisingevent.
Quandary
+2  A: 

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
Fiona Holder
but not in integrated pipeline mode.Well, just found out, I have to switch IIS 7 to classic pipline mode, and it starts working. Funny feature...
Quandary