in reply to Re^2: Multiple Instances
in thread Multiple Instances

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?

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

    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

      I wouldn't. You've got me there, my example would not work. I read the original question as there would be only 1 argument passed to each instance of the JAMES.EXE that was launched. Thus, my intention was to be able to send a single argument to JAMES.EXE - even if that argument happened to be a filename and happened to contain spaces.

      It could be done, but you'd need more detailed parsing of the Perl script's input arguments. The original question provided ~ 1 arg1 2 arg2 3 arg3 ~ where # was the instance and arg# was the single argument to each instance. If there were going to be multiple arguments, you could parse the ARGV looking for 1, then 2, then 3 and after each instance is found, launch into a loop that gathers all arguments until the next number in line is found. That would handle ~ 1 arg1 arg1' 2 arg2 3 arg3 arg3' arg3'' ~