Calling 'system()' ... with parameters

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • asearle
    New Member
    • Sep 2006
    • 39

    Calling 'system()' ... with parameters

    Hi everyone,

    I have a perl script that opens an Access mdb thus:

    system("C:\\Doc uments\ and\ Settings\\asear le\\My\ Documents\\iwh_ dev\\MyAccessDB .mdb");

    This works absolutely fine and, indeed, the perl script happily terminates cleanly when I close the external application.

    Now I would like to implement more automation by adding parameters to the system() call. I need to add the following two parameters:

    /runtime (to start Access in runtime mode)
    /cmd startfull (to pass the command parameter 'startfull' as text)

    I tried tagging these commands on the end of my basic command thus:

    ... MyAccessDB.mdb\ \/runtime\ \/cmd\ starttest");

    but perl simply complained that the file could not be found (i.e. the parameters were interpreted as part of the file name of the file to be called).

    So my question now is whether these parameters need to be passed as separate arguments to the system() call?

    Any tips here would be a great help.

    Regards,
    Alan Searle.
  • asearle
    New Member
    • Sep 2006
    • 39

    #2
    I did some more googling and found the syntax for passing arguments:

    @args = ("command", "arg1", "arg2");
    system(@args) == 0
    or die "system @args failed: $?"

    Excellent!

    But when I tried incorporating this into my command thus:

    ... \\IWH_Rep_Qukam .mdb", "\/runtime", "\/cmd starttest"

    either directly in the system() call or first into the @args array, I found that the program (the Access mdb) would open but none of the parameters that I wanted to pass were recognised.

    Has anyone got a tip here? Maybe there is an error in my syntax?

    Any tips or recommendations would be greatly appreciated.

    Regards,
    Alan Searle.

    Comment

    • GunnarH
      New Member
      • Nov 2006
      • 83

      #3
      Originally posted by asearle
      But when I tried incorporating this into my command thus:

      ... \\IWH_Rep_Qukam .mdb", "\/runtime", "\/cmd starttest"

      either directly in the system() call or first into the @args array, I found that the program (the Access mdb) would open but none of the parameters that I wanted to pass were recognised.
      I would try without those backslashes:
      Code:
      ... \\IWH_Rep_Qukam.mdb", "\/runtime", "\/cmd starttest"
      ---------------------------^------------^
      Or, as regards the first attempt, I'd not escape the space characters that serve as argument separators:
      Code:
      ... MyAccessDB.mdb\ \/runtime\ \/cmd\ starttest");
      ------------------^----------^

      Comment

      • asearle
        New Member
        • Sep 2006
        • 39

        #4
        Thanks very much for the tips.

        Yes, I have played around with all kinds of variations with and without escape characters and with and without spaces and with various different start parameters. I have also 'debug-printed' the variables to check that they are getting to the system() command.

        But somehow they are simply not applied in the windows environment.

        Is this a quirky thing specific to windows (or to ... arrggghhh ... MicroS**t)? Or is it me? I'm not sure.

        Anyway, the new path that I have decided to take is to do away with all parameters (one less thing for the guys in production to worry about) and to apply a 'time controlled default'. This will work in the following way:

        The system will be started by the Perl script (without options) and will hold for about 10 seconds in which time a manual user can cancel the automated processing. If no cancellation is received then the automated process will start.

        I feel quite happy with this solution but it doesn't solve the problem with the passing of parameters (to a windows program).

        I'd be very interested to know if anyone else has experience of successfully passing parameters to other windows programs via the system() command?

        Many thanks,
        Alan Searle.

        Comment

        • GunnarH
          New Member
          • Nov 2006
          • 83

          #5
          Originally posted by asearle
          I'd be very interested to know if anyone else has experience of successfully passing parameters to other windows programs via the system() command?
          I have - without backslashes.

          Comment

          Working...