Problem with system command on Windows

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shrek123
    New Member
    • Aug 2007
    • 23

    #1

    Problem with system command on Windows

    Hi,

    I want to do following operations:

    1. Execute exe from perl script.
    I am using following code:

    system ("start \.\.\\Client\.e xe");

    Perl script is one directory up the directory where Client.exe is present.
    My problem is that the it starts the client.exe with error. Actually the libraries that i have called in the exe program are not getting executed( or called).
    I compiled Winbatch script to get Client.exe.

    2. Open Outlook using perl script.

    system ("start C:\\Program Files\\Microsof t Office\\outlook \.exe");

    It gives an error saying system can not find the file "C;\Progrm" .
    Even if I use

    system ("start C:\\Program\s Files\\Microsof t\sOffice\\outl ook\.exe");

    I gives an error: system can not find the file
    "C;\ProgrmsFile s\MicrosoftsOff ice\outlook.exe ".

    Any direction to solve the problem would ba a great help.
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    First, I am going to assume that you are operating on a Windows operating system. That said, you are not escaping all of the spaces or other special characters. Take a look at this quick script that I just put together and tested. This worked fine:

    [code=perl]
    use strict;
    use warnings;

    system("c:\\Pro gram\ Files\\Microsof t\ Office\\OFFICE1 1\\Outlook.exe" );
    [/code]

    As you can see, not only did I double slash the entire path, but I also slash escaped the spaces in "Program Files" and "Microsoft Outlook". This is a must do to get that working.

    Regards,

    Jeff

    Comment

    • extrastuff123
      New Member
      • Nov 2007
      • 1

      #3
      [code=perl]
      #!/usr/bin/perl -w
      $dpath="\"C:\\P rogram Files\\VMware\\ VMware Workstation\"";
      $vmdpath="\"C:\ \Users\\vijay\\ Documents\\Virt ual Machines\"";
      printf "Enter the name of VM:";
      $name=<STDIN>;
      chomp $name;
      $cmd="$dpath\\v mrun start $vmdpath\\$name \\$name.vmx";
      system $cmd;
      [/code]

      I was able to solve the issue of space in between "Program Files" & "VMware Workstation" using guidelines given above but when I ask user to enter the name of VM & if this "name" contains space like "suse linux 10.2" etc then again I am getting stuck at the same problem mentioned above
      Last edited by eWish; Nov 4 '07, 04:36 PM. Reason: Fixed Code Tag

      Comment

      • eWish
        Recognized Expert Contributor
        • Jul 2007
        • 973

        #4
        I would try this and see if it help your issue. Also use the strict pragma.

        [CODE=perl]my $dpath=q{C:\\Pr ogram Files\\VMware\\ VMware Workstation};[/CODE]

        The q{} is like a single quote. If you use qq{} it is like using double quotes.

        Comment

        • savanm
          New Member
          • Oct 2006
          • 85

          #5
          hi ..

          this single line code is working well ...

          system ("C:\\Progra m Files\\Microsof t Office\\office\ \outlook.exe");

          system ("C:\\Progra m Files\\Microsof t Office\\office\ \POWERPNT.EXE") ;

          I checked....

          Check the path ...

          Comment

          • KevinADC
            Recognized Expert Specialist
            • Jan 2007
            • 4092

            #6
            You should be doing this:

            Code:
            my $cmd = 'C:/Program Files/Microsoft Office/office/outlook.exe';
            system($cmd);
            Windows uses forward slashes or backslashes in directory paths, but backslashes in perl are meta characters and just confuse the issues when used needlessly. Also, use the correct quotes for the situation.

            Comment

            Working...