Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Process not exiting when executed from VB .NET

Status
Not open for further replies.

Shift838

IS-IT--Management
Jan 27, 2003
987
0
0
US
I have a program I am using to select a file and pad the file (binary file) to a specific size. I use the process.start command to kick off a batch file to start the padding of the file specified.

If I launch the batch file from the vb.net form the process never exits. It does pad the file to the specified size, but never exits. starting the batch file from the actual command prompt works with no issue. Depending on the size of the padding will can take longer, so 16k will take longer than 8k, etc.

Any help would be appreciated.

I have the padding file process in a module as follows:

Code:
Sub padfile()
        ' One file parameter to the executable
        Dim blnValue, permanent As Boolean
        Dim intResponse As Integer
        Dim proc As New Process
        Dim sourceName As String = Form1.ListView2.FocusedItem.SubItems(0).Text
        ' The second file parameter to the executable
        Dim c1 As String = Form1.cmbpad.Text & ".bat"
        Dim filetopad As String = " " & Form1.txtpaddir.Text & "\" & sourceName
        permanent = True
        intResponse = MsgBox("PAD Selected File?", vbYesNo)
        If intResponse = vbYes Then
            blnValue = True
        Else
            blnValue = False

        End If
        If blnValue = True Then
            
            proc.StartInfo.UseShellExecute = False
            proc.StartInfo.RedirectStandardOutput = True
            proc.StartInfo.CreateNoWindow = True 'Dont show the cmd window when the program is running
            

            proc.StartInfo.FileName = "cmd.exe"
            proc.StartInfo.Arguments = " " + If(permanent = True, "/K", "/C") + " " + c1 & filetopad
            proc.Start()

            Form1.lblpading.Visible = True

            proc.WaitForExit()
                    

        End If
        Module1.Refresh2()

    End Sub

one of the batch files is below:

Code:
@echo off
:top
if %~z1 GEQ 8192 goto :eof
copy /y %1 /b + nul /a %1 > nul
goto top
 
Have you tested your program with both /K and /C.

In theory (at least) the cmd process should terminate automatically with /C but remain with /K. Since you don't show the cmd window, if you use /K the process will (correctly) not end, but the user will not be aware of this.
 
Softhemc,

You were dead on. removed the /K and it runs with no problem.

thanks!

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top