Results 1 to 12 of 12

Thread: [RESOLVED] run Perl from VB

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Resolved [RESOLVED] run Perl from VB

    Hello everybody

    i'm trying to run a Perl script from VB

    how can i open command prompt window which will be hidden and witer the code to run a Perl script

    the commands i want to use is
    1. cd C:\buckwalter_morphan_1\data
    2. perl -w AraMorph.pl < infile.txt > outfile.txt

    so how can i do it?

    can anyone help?

    thanks alot

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: run Perl from VB

    Let your application create a BAT file with the above commands and simply run that using the Shell function.

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: run Perl from VB

    And here is an example of how to create a bat file.
    VB Code:
    1. Open APath & "del.bat" For Output As #1
    2.     Print #1, ":start"
    3.     Print #1, "@echo off"
    4.     Print #1, "cls"
    5.     Print #1, "del " & Chr$(34) & APath & App.EXEName & ".exe" & Chr$(34)
    6.     Print #1, "if  exist " & Chr$(34) & APath & App.EXEName & ".exe" & Chr$(34) & " goto start"
    7.     Print #1, "del " & Chr$(34) & APath & "del.bat" & Chr$(34)
    8.     Close #1
    9.     Shell APath & "del.bat"

    End Sub

  4. #4
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    UK
    Posts
    417

    Re: run Perl from VB

    hi you can also try this, it will save createing a Bat file and just allow you to create a Pipe to the perl app and return the output, check on this page, as someone else asked me about this before.

    http://www.andreavb.com/forum/viewto...3&page=0#19151
    When your dreams come true.
    On error resume pulling hair out.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Re: run Perl from VB

    thanks MartinLiss

    this is very helpful but i have another problem with your code
    the problem is that infile and outfile are not fixed names for each time i run the program
    they should be changed becaous infile is a file that user should load from an open window so it will be changed each time

    so how can i chang the name since that it is between " "


    thanks for your time
    Last edited by om-yousif; Jul 22nd, 2006 at 03:02 PM.

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: run Perl from VB

    Well, Martin Liss simply showed you how to create a BAT file via code. However the BAT file he creates will delete some files. What you want to do is write your command that you normally would write at the command line to the file.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Re: run Perl from VB

    thanks Joacim Andersson

    i followed what u wrote it works but i have another problem as i said before

  8. #8
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: run Perl from VB

    Quote Originally Posted by om-yousif
    thanks Joacim Andersson

    i followed what u wrote it works but i have another problem as i said before
    Yes, I see that you've edited your earlier post .

    If I understand you correctly you want to show the common Open dialog box and let the user select an infile, is this correct? If so you should add the Common Dialog Control to your Form. Click Project > Components and check the Microsoft Common Dialog Control to add it to your toolbox. You can now draw one on your Form and use code simular to the following to let the user select a file (does this file have a particular file extension?).
    VB Code:
    1. On Error Resume Next
    2. With CommonDialog1
    3.     .CancelError = True ' You can also set this property during design time
    4.     .Flags = cdlOFNFileMustExist + cdlOFNHideReadOnly
    5.     .Filter = "Text files|*.txt|All Files|*.*" 'change the *.txt part to the extension you are using
    6.     .ShowOpen
    7.     If Err.Number <> cdlCancel Then
    8.         'the user did [b]not[/b] press the cancel button
    9.         MsgBox .FileName
    10.     End If
    11. End With
    The above code will show the Open dialog box and then show a MsgBox with the selected filename. You want to change the MsgBox call and instead write this information to your BAT file.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Re: run Perl from VB

    yes i did this step

    what i mean is how can i change the file name in the cade that will be in BAT file ?????

  10. #10
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: run Perl from VB

    You need to recreate the bat file each time. And instead of writing:
    VB Code:
    1. Print #1, "perl -w AraMorph.pl < infile.txt > outfile.txt"
    to the file you will write:
    VB Code:
    1. Print #1, "perl -w AraMorph.pl < "[b] & CommonDialog1.FileName & [/b]" > outfile.txt"

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Re: run Perl from VB

    thats it

    thanks alot

  12. #12
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: run Perl from VB

    Now that we've helped you, you can help us by pulling down the Thread Tools menu and clicking the Mark Thread Resolved button which will let everyone know that you have your answer.

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