Win32::Process and “START” via mime-type

(9/28 JimPossible 2, Evil Windows FUD dragons 0)!:

When using system/exec 2 launch process, such as M$-Excel, in a Win32::GUI program, abUser seemes to have to move mouse over app-window once 2 get subprocess window 2 appear, then again to get the file loaded into the app. Must be something w/Win32::GUI’s event-loop (works fine in Tk -hint -hint ;). Anyway, “Learning Perl on Win32 Systems”, p155 describes Win32::Process, but example is for a specific app. In my case, I do not know the path to M$-Excel on various clients + want to be able to select app based on datafile’s mime-type. After much t&e, discovered to use “cmd.exe” via $ENV{COMSPEC} as follows:

Win32::Process::Create($process, #OUT parameter for Create, ~used anywhere else!
$ENV{COMSPEC}||”C:\\WINDOWS\\system32\\cmd.exe”, #JUST IN CASE COMSPEC NOT DEFINED.
“cmd /C C:\\path\\to\\my\\file.xls”, #OUR COMMAND.
0, DETACHED_PROCESS, ‘.’) || die “Spawn Excel: $!”;

1=does, 0=does not inherit open file-handles (we used “0” here).
DETACHED_PROCESS = no console access for new process.
“.” Not sure, I guess set cwd[new process] to current directory[current program]???

This seems to get the job done!

Advertisements

Feel Free to Comment (Name/Email/Website optional):

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: