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

How to use shell script in visual basic

Status
Not open for further replies.

dawtes

Programmer
Jun 23, 2005
31
US
I have a .EXE file that i would like to run in visual basic.I did try to use shell script but it does not give me the result i am expecting to get. I need to double click for the exe file to be executed and i do not really know if i can do this inside the visula basic code.
Private Sub Command1_Click()
Dim p1 As Integer
Dim L As Integer
Dim I As String
Dim FileString As String



FileCopy "J:\IO\qebsfnam\pass2ebs", "C:\pass2ebs.txt"

If Dir("C:\pass2ebs.txt") <> "" Then
Open "C:\pass2ebs.txt" For Input As #1
Else
Message = "File not found"
End If
Exit Sub
Rem Open "C:\pass2ebs.txt" For Input As #1
Open "C:\pass.txt" For Output As #2
Do While Not EOF(1)
Line Input #1, FileString
L = Len(FileString)
p1 = InStr(FileString, "/")
I = LTrim(Left(FileString, 6))

If (I = "ITEM01" And p1) Then
If Mid(FileString, p1 - 4, 1) <> "." Then
FileString = Left(FileString, p1 - 4) & "." & Right(FileString, L - p1 + 4)
Print #2, FileString
Else: Print #2, FileString
End If
Else: Print #2, FileString
End If
Loop
Close #1
Close #2

Kill "C:\pass2ebs.txt"
Name "C:\pass.txt" As "C:\pass2ebs.txt"

End Sub




Private Sub Command2_Click()
Shell ("c:\gen.exe")
End Sub
 
If the file to launch is exe then:
Shell "filepath\finame.exe" [, **]
where ** is optional argument for the app state (vbNormalFocus etc)

Example: Shell "c:\gen.exe"


If the file to launch is not exe then:
Shell "application path.exe abc.txt" [, **]

Example: Shell "C:\windows\notepad.exe abc.txt"
Example: Shell "C:\program files\... \word.exe abc.doc
 
I did just use that but I do not seem to have a luck with it.It works fine when i use other executable files like notepad.exe , However For this GEN.EXE file to be executed I do need to to make a double click on it for me to get the result.I am not sure how i am able to do that inside the visual basic.
 
This gen.exe is a windows app, console app, what ?
 
It is a program created by the third party for our bidding process.what is does is when i run it create a file we use for our online bidding.I was hoping to write a simple script to copy this file from server and run it and generate those files
 
Is there an error when the shell is executed?

What i thought of is: The copy from the server is not finished and during the download proccess the shell is executed. Can you try something like this?

' code in a button:

DoEvents
'call the sub to download the file to save it in "c:\"
Shell "c:\gen.exe"
 
Err...

If Dir("C:\pass2ebs.txt") <> "" Then
Open "C:\pass2ebs.txt" For Input As #1
Else
Message = "File not found"
End If
Exit Sub ' should this be placed here ?? Or somewhere between If and End If ?


One other suggestion: these #1 and #2, if those numbers are in use -> problem <-

So: dim f as freefile()
and: #f instead of #1 and #2
at the end: Close(f)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top