in reply to System command with quotes and variables

How are you quoting that string? I recommend putting together a list form of the arguments. The bare string '/user:domain\$user' is unlikely to do right. If interpolated, the '$' will be taken as literal because '\' escapes the '$'. I don't know what string is meant there. Try,

system 'runas', "/user:domain/$user", 'c:\Program Files\Internet Explorer\iexplore.exe', '"c:\"' and die $?;
The peculiar and logic is because system returns false on success. Most of perl isn't like that. I don't know what 'runas' looks for in its arguments, so you need to use your familiarity with that program to get this right.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: System command with quotes and variables
by mellin (Scribe) on Apr 16, 2007 at 06:47 UTC

    I finally wrote it just like this:

    my $command = "C:\\Windows\\system32\\runas.exe /user:ctldomain\\$us +er \"c:\\Program Files\\Internet Explorer\\iexplore.exe \"c:\""; system($command) or print "error running command: $!\n" and exit;

    But i have to reconsider using a list as suggested by you and others.

      You can use forward-slash / or back-slash \ as a directory separator on Windows. Forward slash is easier since you don't have to escape it (cmd.exe and Windows Explorer only support \).
      You might also like to consider using qq to avoid escapes.