Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 进程意外结束_.net - Fatal编程技术网

.net 进程意外结束

.net 进程意外结束,.net,.net,我正在.net服务中启动一个新进程,并在控制台中运行winrar。 它适用于没有大量文件和单个文件的文件夹,但在归档大文件夹时,该过程似乎会在某个时候停止。 我是说它似乎停止了,因为 当我返回输出时,存档未完成 触发文件夹刷新的主进程将再次启动 下面是运行该流程的一段代码: Private Sub log(text As String) IO.File.AppendAllText("log.txt", text) End Sub Private Sub SortOutputHandle

我正在.net服务中启动一个新进程,并在控制台中运行winrar。 它适用于没有大量文件和单个文件的文件夹,但在归档大文件夹时,该过程似乎会在某个时候停止。 我是说它似乎停止了,因为

当我返回输出时,存档未完成 触发文件夹刷新的主进程将再次启动 下面是运行该流程的一段代码:

Private Sub log(text As String)
    IO.File.AppendAllText("log.txt", text)
End Sub

Private Sub SortOutputHandler(sendingProcess As Object, _
     outLine As DataReceivedEventArgs)
    If Not String.IsNullOrEmpty(outLine.Data) Then
        numOutputLines += 1
        log(Environment.NewLine & "[" _
                     & numOutputLines.ToString() & "] - " _
                     & outLine.Data)
    End If
End Sub

Private Function RunCmd(ParamArray commands As String()) As String
    Try
        If Not sortOutput Is Nothing Then
            sortOutput.Length = 0
        End If

        Dim returnvalue As String = String.Empty

        Dim info As New ProcessStartInfo("cmd")
        info.UseShellExecute = False
        info.RedirectStandardInput = True
        info.RedirectStandardOutput = True
        info.CreateNoWindow = True

        Using process__1 As Process = Process.Start(info)
            AddHandler process__1.OutputDataReceived, AddressOf SortOutputHandler
            process__1.BeginOutputReadLine()

            Using sw As StreamWriter = process__1.StandardInput
                For Each command As String In commands
                    sw.WriteLine("chcp 65001")
                    sw.WriteLine(command)
                    log(command)
                Next
                sw.Close()
            End Using
            process__1.WaitForExit()
        End Using

        returnvalue = sortOutput.ToString

        info = Nothing
        Return returnvalue
    Catch ex As Exception
        Return Nothing
    End Try

End Function

Private Sub zip(destinationFolder As String, outputFile As String, sourceItem As String) 
    Dim results As String = RunCmd("rar.exe u """ & destinationFolder & outputFile & """ -m3 -w" & workingDir & " """ & sourceItem & """ ")

End Sub

作为一个输出,当从命令行运行RAR时,我们期望的是什么,但是它只是在归档中间的某个点结束:

[3945] - Adding    \\servername\path1      51%  OK 
[3946] - Adding    \\servername\path2      51%
[3947] - C:\Windows\system32>
存档文件不完整,并且存在System.IO。在服务的主块中引发异常,抱怨它找不到传递到命令行的源的子文件夹之一的路径的一部分

我想知道输出的异步读取是否正确? 在我看来,这是因为我在日志文件中逐行获得了输出,但我遇到了同样的问题,尽管在同步读取输出时无法获得相同的日志


谢谢

问题出在代码的这一部分:

Catch ex As Exception
    Return Nothing
End Try

任何可能发生的异常都会被忽略,函数会立即返回。您至少可以返回异常消息,而不是什么都不返回,这可能会给您一个关于发生了什么以及如何解决这种情况的提示。

这是一个稍微精简的代码版本,该catch中还有一个额外的调用来记录异常。代码的这一部分基本上没有异常,我得到的唯一异常是在调用zip Sub的服务的主块中。因为服务的主要部分被重复的唯一原因是因为rar没有首先完成,我认为这可能与它无关