CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14
  1. #1
    Join Date
    Dec 2012
    Posts
    20

    use of shell for calling perl from vb 6.0

    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........

  2. #2
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: use of shell for calling perl from vb 6.0

    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.

  3. #3
    Join Date
    Dec 2012
    Posts
    20

    Re: use of shell for calling perl from vb 6.0

    yes, i need to run it from vb only.......

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: use of shell for calling perl from vb 6.0

    You create a script then call it from VB6? That sounds evil to me...
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Dec 2012
    Posts
    20

    Re: use of shell for calling perl from vb 6.0

    WoF, i used the code.its giving runtime error 5 invalid procedure call or argument.......

  6. #6
    Join Date
    Dec 2012
    Posts
    20

    Re: use of shell for calling perl from vb 6.0

    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....

  7. #7
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: use of shell for calling perl from vb 6.0

    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....
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  8. #8
    Join Date
    Dec 2012
    Posts
    20

    Re: use of shell for calling perl from vb 6.0

    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.....

  9. #9
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: use of shell for calling perl from vb 6.0

    Q
    how can i call a perl script from a vb
    A
    i hav already written the code to call perl from vb
    Looks like you've answered your own question, to me.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  10. #10
    Join Date
    Dec 2012
    Posts
    20

    Re: use of shell for calling perl from vb 6.0

    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.....

  11. #11
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: use of shell for calling perl from vb 6.0

    Post the answer when it works (for the next person to read this)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  12. #12
    Join Date
    Dec 2012
    Posts
    38

    Re: use of shell for calling perl from vb 6.0

    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.

  13. #13
    Join Date
    Dec 2012
    Posts
    20

    Re: use of shell for calling perl from vb 6.0

    dglienna, of course i will once it works.......

    cereal killer, yes, i asked how to call perl from vb and you gave the idea of shell....i took it up......thank you.....

  14. #14
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: use of shell for calling perl from vb 6.0

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured