Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide cmd window when run perl in python?

Tags:

python

perl

I write the main application with python and build it to windows *.exe file, and now need to call a 3rd party perl script.

I use,

cmd = "perl fileconverter.pl"
subprocess.call(cmd)

Everything works well except the cmd window, which will pop up when subprocess.call(cmd) is called. Question is, how to hide the cmd window in this situation?

like image 840
Rui Avatar asked Dec 30 '25 15:12

Rui


1 Answers

You can use wperl instead of perl.


If your program is running in a console, perl should reuse the same console.

>perl -e"system 'perl -Esay+123'"
123

(I don't have Python installed, but the same applies no matter what launches perl.)

But maybe the Python is running without a console. Then perl will create itself a console.

Another answer shows you how to hide this console when using Python, and it's a great solution. But there's a simple Perl-specific option you can also use.

Strawberry Perl (and I think ActivePerl, and probably all builds of Perl for Windows) provide not just perl.exe, but wperl.exe.[1] The latter is identical to the former, except it uses a hidden console.[2] So all you would need to do is change perl to wperl.


  1. I don't count builds of Perl for unix emulation environments (Cygwin, MSYS, MSYS2) as Windows builds of Perl.
  2. The binaries differ by only one bit.
like image 106
ikegami Avatar answered Jan 02 '26 06:01

ikegami