in reply to Multiple Instances

Rather than using the ~ 1 "M" 2 "007" 3 "MI6" ~ format, just provide the arugments you want to each instance of the EXE to the Perl script as arguments.

#!/usr/bin/perl use strict; foreach (@ARGV) { system ("James.exe $_") }

Then simply use:

bond.pl M 007 "MI-6" "this is how youd send multiple to one EXE instan +ce"

to run

James.exe M James.exe 007 James.exe MI-6 James.exe this is how youd send multiple to one EXE instance

Replies are listed 'Best First'.
Re^2: Multiple Instances
by GrandFather (Saint) on Mar 12, 2009 at 00:51 UTC

    How do you provide the double quotes for double quoted arguments - for example, when there are paths or file names with spaces in them?


    True laziness is hard work

      I tested this on Windows XP with ActiveState Perl v5.8.8

      #!/usr/bin/perl use strict; foreach (@ARGV) { print "Staring: NOTEPAD $_\n"; system ("start notepad $_") }
      {C} > test \AUTOEXEC.BAT "\Documents and Settings\601404184\My Documents\mcafee.txt" test.pl
      Staring: NOTEPAD \AUTOEXEC.BAT
      Staring: NOTEPAD \Documents and Settings\601404184\My Documents\mcafee.txt
      Staring: NOTEPAD test.pl

      {C} >

      NOTE: That's the output you see in CMD.EXE window. Also, three instances of NOTEPAD.EXE open, with each file in one of the Notepads.

      Does that answer the question re: double-quotes for file names? The second argument had spaces and the first two had backslashes, also could be an issue, but handled fine. I understand slashes would be the other way on *nix path names and spaces would need to be escaped so I don't know how well this would work. Also, you wouldn't use "start" in the system() call; rather, an ampersand (&) to launch the program in the background perhaps?

        That doesn't address the issue. Let me rephrase it slightly: suppose the application requires multiple arguments, some of which need to be double quoted. How then do you manage the quoting? For example, if the application is 'copy' how would you perform the equivalent of:

        copy "this one.txt" "that one.txt"

        True laziness is hard work