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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

working with "Shell command"

Status
Not open for further replies.

rafiu

Programmer
Jul 3, 2007
14
US

im using "shell" command in a Form to run a process which was created in Perl. I will like to stop any user from exiting from the form unless the process is done running. what code can I use. Thank you in advance

param1_folderLoc = Convert.ToString(totalSelected.Item(index))
procID = Shell("perl C:\\stwich_profile_copy.pl " & param1_folderLoc
 
rafiu,

Search MSDN on Internet for System.Diagnostics.Process class. You can use Process.Start() to start an external process and Process.WaitForExit() method to accomplish your task.

Hope it helps.

 
I tried the step you gave me but when I tried to run the process, I got this error "system cannot find the file specified". I save the perl script in my "c:" drive and it should be able to find it. Below is my code maybe you will have any help you can render.


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim path As Integer
Dim returnValue As String()
returnValue = System.IO.Directory.GetFileSystemEntries("o:\\T2000\Profiles")
For path = 0 To UBound(returnValue)
ListBox1.Items.Add(returnValue(path))
Next
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim totalSelected As IList = ListBox1.SelectedItems()
Dim index As Integer
'Dim procID As Integer
Dim param1_folderLoc As String
For index = 0 To (totalSelected.Count() - 1)
param1_folderLoc = Convert.ToString(totalSelected.Item(index))
Dim pID As Process = System.Diagnostics.Process.Start("perl C:\\stwich_profile_copy.pl" & param1_folderLoc)
pID.WaitForExit()
' display results
ListBox2.Items.Add(" process was closed at: " & _
pID.ExitTime & "." & _
System.Environment.NewLine & "Exit Code: " & _
pID.ExitCode)
pID.Close()
Next
End Sub
 
Try rephrasing following line of code from your code to the one given below.

Dim pID As Process = System.Diagnostics.Process.Start("perl C:\\stwich_profile_copy.pl" & param1_folderLoc)

to

Dim pID As Process = System.Diagnostics.Process.Start("perl", "C:\\stwich_profile_copy.pl " & param1_folderLoc)

Also try replacing perl with absolute path to perl e.g. C:\PerlFolder\perl.exe.

Hope it helps.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top