How can I see Process being executed?

  • Thread starter Thread starter Mugsy_in_Houston
  • Start date Start date
M

Mugsy_in_Houston

Guest
I have a loop that is supposed to zip every folder in a particular location. It works exactly once. The second time through the loop, no zip file is created. My output window reports only "Error: No such archive". Stepping through the code, the "foundDir" is correct, so the Shell Command being executed must be bad, but I can't see the command it was trying to execute.

Here is my code. It invisibly executes "7za.exe" (the 7zip archiver CLI) with arguments and "foundDir" name, and sends the screen output to a textbox:

Dim oProcess As New Process()
Dim oStartInfo As New ProcessStartInfo(strSrcPath & "7za.exe", "-?") ' "-?" argument shown here is simply so I know it supports switches.
oStartInfo.UseShellExecute = False
oStartInfo.RedirectStandardOutput = True
oProcess.StartInfo = oStartInfo
Dim sOutput As String

For Each foundDir In My.Computer.FileSystem.GetDirectories(strSrcPath & "\Plugins\")
' Check for existence of zip file at target. If it exists, prompt for overwrite. If not, skip.
bolSkip = False ' reset
strSource = foundDir.Substring(InStrRev(foundDir, "\")) ' Get just the foldername from the end of the path.
strCompletedZip = txtPrefix.Text & strSource & ".zip" ' Optional "Prefix" entered by user.
If My.Computer.FileSystem.FileExists(strDestPath & "\" & txtPrefix.Text & strSource & "\Plugins\" & strSource & ".zip") = True Then
Dim response = MsgBox("Target '" & strSource & ".zip' already exists!" & vbCrLf & vbCrLf & "Overwrite?", MsgBoxStyle.YesNo)
If response = MsgBoxResult.No Then bolSkip = True
End If
If Not bolSkip Then ' Compress & move.
txtOutput.Text = "" ' Clear output window.
oStartInfo.Arguments = "a -tzip " & foundDir
oProcess.Start()
Using oStreamReader As System.IO.StreamReader = oProcess.StandardOutput
sOutput = oStreamReader.ReadToEnd()
txtOutput.AppendText(sOutput & vbCrLf) ' Append output w/o reassigning/printing the entire contents over & over. "Append" forces window to scroll.
End Using
My.Computer.FileSystem.MoveFile(foundDir & ".zip", strDestPath & "\" & txtPrefix.Text & strSource & "\Plugins\" & strSource & ".zip", True)
' Delete source folder after compressing.
My.Computer.FileSystem.DeleteDirectory(foundDir, FileIO.DeleteDirectoryOption.DeleteAllContents)
End If
Next

First time through the loop, it correctly finds the first folder, compresses it, then moves it to a location specified by the user. Second time through the loop, it sees the next folder, but when it executes "oProcess.Start()", no zip file is created and I have no idea why. I need to see the command being executed (if any) but I can't figure out how.

Any help is appreciated. TIA.

Continue reading...
 
Back
Top