fdesar has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I tried many things and I'm still stuck on a stupid problem with Window.

I have a script running under wperl as I don't need any console window for my script, all its IO being handled by pipes.

But I need to be able to call a cmd command to display a PDF file in the default viewer (ie explore).

So I tried issuing the simple command :

qx{start "$pdf" /b };

and whatever I do (even using the /b option), it begins first by opening a console window before running the explorer.

Do you think of a way to get rid of this silly unexpected console ?

(Or any other way to display the PDF file...)

Thanks for any advise,

F.

Replies are listed 'Best First'.
Re: Win32 wperl open Console when system
by Corion (Patriarch) on Jan 21, 2020 at 10:19 UTC

    Using cmd.exe to launch the default program will always open a console window (if none is open already), because cmd.exe is a console program:

    qx{start "$pdf" /b };

    If you want to avoid that, don't involve the start command of cmd.exe and instead do what the command does, by using the AssocQueryStringA function, as in this Stackoverflow post. Doing so shouldn't be too hard using Win32::API, but I can't test it right now.

      unfortunatly, .pdf has no default association in HKEY_CLASS_ROOT for .pdf :-(

      And if I directly run "C:\Program Files\Internet Explorer\iexplore.exe" file.pdf, it asks what to do with the file instead of displaying it directly...

        You first said "explorer" (files) now you say iexplore (internet)?

        These are two different programs.

        this C:\>C:\Windows\explorer.exe \tmp\xxx.pdf works for me from the console (cmd.exe)

        update

        this doesn't :/

        perl -e"`C:/Windows/explorer.exe /tmp/xxx.pdf`"

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Re: Win32 wperl open Console when system
by Anonymous Monk on Jan 21, 2020 at 09:25 UTC

      Thanks for your answer, but it doesn answer my question at all !

      I'm already running wperl with no problem, except that I need to run a cmd command from it and it always opens an annoying console window just to launch the start command which is immediately exiting.

      This is this case I'm trying to solve...

        But the linked thread looks good to me.

        Did you look into it and try all listed options?

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

        I just told you how to hide console and how i found that answer