Results 1 to 8 of 8

Thread: Passing arguements in a Shelled program

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2003
    Location
    singapore
    Posts
    86

    Unhappy Passing arguements in a Shelled program

    I have noticed that my Shell function can only run a program without any arguments. I've tested it with many samples already but I can't find any which can run with arguments. How to do it? example, if i were to type in the command line... i use something like c:\.....\..\perl test.pl 2 02/03/2003 14:15:27 3 80 so, s u can c, i've got 5 arg being passed(2 ,02/03/2003 ,14:15:27, 3 ,80 ).This can work. But when I want to use the Shell function to run the program in the same manner, it doesn't. How am I to get about doing this.? pls help.

  2. #2
    Addicted Member Cyberius's Avatar
    Join Date
    Jan 2003
    Location
    Australia
    Posts
    145
    how exactly are you making use of shell in your app? post a piece of the source here or just that line or something.
    -=[Ç¥ßè®Ìú§]=-

    How many microsoft employees does it take to change a lightbulb? None, they simply define darkness as the new industry standard.

    CAUTION: OVERCLOCKING A 386 TO 5Ghz MAY BE HAZARDOUS

  3. #3
    Lively Member blaff's Avatar
    Join Date
    Nov 2002
    Location
    Germany
    Posts
    69
    I had the same problem. My workaround:

    1. Create a batch-file in the temp folder. In this batch file you can call the program with all arguments.
    2. Execute the batch file.
    3. Delete the batch file!
    _____
    blaff

  4. #4
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177
    Have you considered using the ShellExecute API? I thik I have included all the pertinent code...
    VB Code:
    1. Public Const gSW_SHOWNORMAL       As Integer = 1&
    2. Public gScr_hDC                   As Long
    3.  
    4. Public Declare Function ShellExecute Lib "shell32.dll" _
    5.                Alias "ShellExecuteA" (ByVal hwnd As Long, _
    6.                                       ByVal lpszOp As String, _
    7.                                       ByVal lpszFile As String, _
    8.                                       ByVal lpszParams As String, _
    9.                                       ByVal lpszDir As String, _
    10.                                       ByVal FsShowCmd As Long) As Long
    11. Public Declare Function GetDesktopWindow Lib "user32" () As Long
    12. ..
    13. gScr_hDC = GetDesktopWindow()
    14. ..
    15. Dim Result As Long
    16. Result = ShellExecute(gScr_hDC, "Open", "some prog.exe", _
    17.                       "some param list", "C:\", gSW_SHOWNORMAL)
    On another note, if you want to use the previous example, you can add the "delete somebatchfile.bat" line to the batch file (as the last line to execute) and have it clean up after itself.
    Last edited by ccoder; Apr 7th, 2003 at 10:31 AM.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2003
    Location
    singapore
    Posts
    86
    what else should i add in that code? Im actually want to run a perl program to create some text files. In the command line...tis is wat I do: c:\windows\desktop\....\perl CreateActivity.pl 2 20/03/2003 8 30". What i guess is, duing execution time, VB shell truncates the space aft the word "perl" so the arguments nor the perl program is executed...hope u understand what I'm saying..Thankx alot for ur help.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Mar 2003
    Location
    singapore
    Posts
    86
    what else should i add in that code? Im actually want to run a perl program to create some text files. In the command line...tis is wat I do: c:\windows\desktop\....\perl CreateActivity.pl 2 20/03/2003 8 30". What i guess is, duing execution time, VB shell truncates the space aft the word "perl" so the arguments nor the perl program is executed...hope u understand what I'm saying..Thankx alot for ur help.Note(2, 20/03/2003 ,13:15:00,8 ,30) are the 5 arguments which I need to pass in...

  7. #7
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177
    Hmmm. It looks like perl is the executable, CreateActivity.pl is a parameter to perl and the rest are parameters to CreateActivity.pl.

    Try:
    VB Code:
    1. Result = ShellExecute(gScr_hDC, "Open", "c:\windows\desktop\....\perl CreateActivity.pl", _
    2.                       "2, 20/03/2003 ,13:15:00,8 ,30", "C:\", gSW_SHOWNORMAL)
    If that doesn't work, try:
    VB Code:
    1. Result = ShellExecute(gScr_hDC, "Open", "c:\windows\desktop\....\perl", _
    2.                       "CreateActivity.pl 2, 20/03/2003 ,13:15:00,8 ,30", "C:\", gSW_SHOWNORMAL)

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Mar 2003
    Location
    singapore
    Posts
    86
    I've tried both ways already ..No errors nor any changes..My program is supposed to create a text file based on the param passed. It works when run from command line but not in the program.. U gav the above code rite? Is tat all or do I need to add in some other codes.?I've got a sample code on this ..
    PHP Code:
    Dim objWSH As Object
    'Do all the stuff before you call the Perl program...

    '
    instaciate the WScript.Shell object
    Set objWSH 
    CreateObject("WScript.Shell")

    'Run the perl program, waiting for completion - execution will pause
    here until the program has completed
    objWSH
    .Run "c:\windows\desktop\CreateAct\perl CreateActivity.pl  2 03/02/2003 13:30:00 8 30"1True  '1 09/10/2001 13:30:00 8 30"

    '
    clean up
    Set objWSH 
    Nothing

    'continue on with processing. When you get here the perl program will have finished. 
    . Can ur solution be used to fit in this ...How?Thankx for ur reply.[
    Last edited by ITboy; Apr 7th, 2003 at 09:26 PM.

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