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

executing exe in vb.net 1

Status
Not open for further replies.

josie2007

Technical User
Apr 14, 2007
90
US
The program just does not execute...but when I go run the exe manually it works fine. any clue?
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
System.Diagnostics.Process.Start("C:\Expedite\Gen.exe")

End Sub
 
yes,when I run it like you suggested it genterate the files for me
 
Try running this... just curious.


Try
System.Diagnostics.Process.Start("C:\Expedite\Gen.exe")
Catch ex as System.Exception
Msgbox(ex.tostring)
End Try

Senior Software Developer
 
Thinking about it, my last suggestion may not catch anything. I'm confused though because I've never had any trouble using this.

Have you tried putting a break point in and stepping through this? The only thing I can think of right now is that somehow the thread is dying.


Senior Software Developer
 
thanks again for your help. I did not get any exception thrown out.
 
Are you using Windows Server 2003?

If you place a Thread.Sleep(5000) right after the Process.Start line, is there any change in behavior?

Senior Software Developer
 
What exactly does "C:\Expedite\Gen.exe" do? And how does your VB program interact with "C:\Expedite\Gen.exe", and/or the output from "C:\Expedite\Gen.exe"?



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Thank you for the help again. I might not be clear with my question and I will try to clarify it a little further. this gen.exe file will generate EBS files by using Pass2ebs.txt file both gen.exe and pass2ebs.txt are in the same folder called expedite.I donot know if this will help ...thanks so much for the help
 
Try this and let us know:

-------------
Dim p As New Process
p.StartInfo.FileName = "C:\Expedite\Gen.exe"
p.Start()
Threading.Thread.Sleep(5000)
If p.HasExited Then
MsgBox("Started: " & p.StartTime & ", Ended: " & p.ExitTime & ", ExitCode: " & p.ExitCode)
Else
MsgBox("Still Running.")
End If
--------------

Senior Software Developer
 
To use the code as suggested by SiriusBlackOp, you will need to add

[tt]Imports System.Diagnostics.Process[/tt]

to the top of your class

[vampire][bat]
 
Here is what I got now
Unable to open Input file pass2ebs.txt ..I have this file in the Expedite folder and I do not know why it is not able to open it.when I run the gen.exe in the expedite folder it genertes the file for me.

started:4/26/2007 12:06:35PM
Ends:4/26/2007 12:06:35PM
exitcode=1
 
Is your program - the one calling gen.exe - modifying pass2ebs.txt? If so, make sure you are closing it before trying to run gen.exe.



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
yes, the program is modifying pass2ebs.txt file. and every thing is closed.Here is the entire code

Imports System.IO
Imports Microsoft.VisualBasic
Imports System.Diagnostics.Process
Public Class frmEbs

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim NewEbsFiles As String
Dim OldEbsFiles As String
Dim p1 As Integer
Dim TextLength As Integer
Dim TextFound As String = ""
Dim FileString As String = ""
Dim AllLines As String = ""

NewEbsFiles = "W:\IO\qebsfnam\pass2ebs"
OldEbsFiles = "C:\Expedite\gen\pass2ebs.txt"

If File.Exists(NewEbsFiles) = True Then
If File.Exists(OldEbsFiles) = True Then
File.Delete(OldEbsFiles)
End If
File.Copy(NewEbsFiles, OldEbsFiles)
'MsgBox("New EBS file (pass2ebs.txt) has been copied over to Expedite folder")
End If

Dim ebsFileReader As New StreamReader(OldEbsFiles)
Dim ProposalItem As String = ""
Do While ebsFileReader.Peek() <> -1

ProposalItem = ebsFileReader.ReadLine() & vbNewLine
TextLength = Len(Trim(ProposalItem))
p1 = InStr(ProposalItem, "/")
TextFound = LTrim(Microsoft.VisualBasic.Left(ProposalItem, 6))
If (TextFound = "ITEM01" And p1 > 0) Then
If Mid(ProposalItem, p1 - 3, 1) <> "." Then
ProposalItem = Microsoft.VisualBasic.Left(ProposalItem, p1 - 4) & "." & Microsoft.VisualBasic.Right(ProposalItem, TextLength - p1 + 4)
End If
End If
AllLines = AllLines & ProposalItem
Loop
Dim WriteEbsFiles As String = "C:\Expedite\pass2ebs.txt"
Dim ebsFileWriter As New StreamWriter(WriteEbsFiles)
ebsFileWriter.WriteLine(AllLines)
ebsFileWriter.Close()
ebsFileReader.Close()

End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
System.Diagnostics.Process.Start("C:\Expedite\Gen.exe")

End Sub
End Class
 
Ok. So we now know that it started, and that it crashed. I'm not sure how you found the error of "Unable to open Input file pass2ebs.txt"... But that is Great!

Did you create gen.exe or is this a third party app?

Try Setting p.WorkingDirectory = "C:\Expedite\"

Senior Software Developer
 
You could try using a StartInfo block for the process to enable you to set the starting directory for Gen.Exe. The syntax would be similar to that in the posts towards the end of: thread796-1360713


Hope this helps.

[vampire][bat]
 
Correction:

Change:
System.Diagnostics.Process.Start("C:\Expedite\Gen.exe")


To:
Dim p As New Process
p.StartInfo.FileName = "C:\Expedite\Gen.exe"
p.StartInfo.WorkingDirectory = "C:\Expedite\"
p.Start()
------------
My thought is that gen.exe is using StartupDirectory and it is looking in the debug folder of your project. Could also try coping the pass2ebs.txt into your debug directory to test this.

Senior Software Developer
 
SiriusBlackOp, WorkingDirectory is part of StartInfo, not Process.


Hope this helps.

[vampire][bat]
 
SiriusBlackOp thank you for the help. I just did like your suggested above and now it worked.You are awesome.I also thank all of you for your help and suggestions. thanks
 
will it be possible to run to exe programs together like this?
this is the new line I just added
p.StartInfo.FileName = "C:\Expedite\eblib.exe /a Josie *.ebs"



Else
Dim p As New Process
p.StartInfo.FileName = "C:\Expedite\Gen.exe"
p.StartInfo.FileName = "C:\Expedite\eblib.exe /a Josie *.ebs"
p.StartInfo.WorkingDirectory = "C:\Expedite\"
p.Start()

TextBox1.Text = "EBS Files Has Been Generated.It Is On C:\Expedite Folder " & vbNewLine
TextBox1.Text += "Now You Can Transfer these EBS files to Bidx."
GetEbsFiles.Enabl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top