i have a vb 6.0 program that creates a perl program during runtime...any idea how i can call that perl in next step??am suggested to use shell function of which i know little...how can it be implemented?searched net but didnt find any satisfying answer........
The shell function can be used to execute another program from within your VB6 application. You can run bat, cmd, vbs, exe and other directly executable files like:
Code:
dim proc as long
proc = Shell("MyScript.vbs")
The ProcessID proc you get back can be used to wait until the shell execution has finished.
I'm not sure about Perl, though. But if you are able to run a Perl script by doubleclick from the desktop, you can use the code like I described.
dglienna,well, let me explain......i need remote login to different systems to view the alarms on them....for that i hav written a perl script...now the ip addresse to login needs to be changed everytime the script is run...and the ip addresses are selected by the ids of the particular systems(that am loggin in) that is stored in a database(which am retrieving through vb 6.0).......hence i've written code so that the perl script is created during runtime with appropriate ip address......and then now i need to run that perl prog and save those retrieved alarms in a text file......it must be called from vb then.....no? then i need to move the text file value to a string variable in vb 6.0 and then update the database.....dat completes the work........there may be shortcuts......but am learning and doing at same time.......so i found this way.......any suggestions??
i'l get stuck to this work until it wont get finished....
You started by saying that VB6 writes a script and calls it. As bad as that may be, you now want help to modify the IP addresses in the scripts? We haven't seen any code or scripts....
I didnt want help to modify the ip addresses....perhaps u fail to understand my query......i asked clearly how can i call a perl script from a vb program..dats all...if i hav already written the code to call perl from vb, there would have been no need for me to ask it.....right?
And i think its a forum to 'give help' and 'want help'......not to criticize anyone for wanting help.....
Thank you dglienna.....
you missed the 'if' in your answer...........if i would have already written it, then there was no need to ask....anyway......i found a way...lets c if it works.....
I had already said you in another thread you opened in this same forum that is not possible what you want to do. And more it has no sense:
why do you have to call a script when you can easly program it within your own program? It has more sense to call a third-part software when you can't develope the whole program yourself, but if you only need a feature, you can develope it yourself, don't you?
Moreover it's difficult to manage another software directly from your project.
This is my opinion, then you are free to do as better you believe.
As I understand you want to run multiple scripts one after the other.
You have to understand this about the Shell() function: It will start the script, but then will immediately continue execution within the VB program. So the second script might be generated while the first one is still running, thus creating an error.
I think you want to wait within the VB program until one script has finished execution before you create the next one.
Here is how you achieve this:
Code:
Option Explicit
Const SYNCHRONIZE = &H100000
Const INFINITE = &HFFFF 'Wait forever
Const WAIT_OBJECT_0 = 0 'The state of the specified object is signaled.
Const WAIT_TIMEOUT = &H102 'The time-out interval elapsed, and the
'object’s state is nonsignaled.
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Sub RunShellAndWait()
Dim lPid As Long
Dim lHnd As Long
Dim lRet As Long
lPid = Shell("command.com /c Myscript", vbNormalFocus)
If lPid <> 0 Then
lHnd = OpenProcess(SYNCHRONIZE, 0, lPid) 'Get a handle to the shelled process.
If lHnd <> 0 Then 'If successful, wait for the
lRet = WaitForSingleObject(lHnd, INFINITE) ' application to end.
CloseHandle (lHnd) 'Close the handle.
End If
MsgBox "Just terminated.", vbInformation, "Shelled Application"
End If
End Sub
After everything is running you will want to remove the MsgBox command so as everything runs without further intervention.
Bookmarks