After this: ruby executable won't start,
Now i have another issue with the following simple script:
require 'tk'
require 'tkextlib/tile'
root = TkRoot.new()
button = Tk::Tile::TButton.new(root) {text "Hello World"}.grid
button.command {system("ipconfig > info.txt")}
Tk.mainloop()
If i click the Hello World button, so the Windows cmd console will pop up for less then one second. No outputs on it, i also tried to redirect its output to a file and its empty.
If i run my scprit like this:
G:\WinRuby\efdsk>ruby efdsk.rb
There are no problems.
So this issue will appear when i run my exe built with ocra, and also when i run my script like this:
rubyw efdsk.rb
If i comment the following line,
button.command {system("ipconfig > info.txt")}
The issue will disappear, so i think it's something related to system(). I also tried to replace the previous line with this:
cmd="ipconfig > info.txt"
Open3.popen3(cmd) {|stdin, stdout, stderr, wait_thr|}
But the cmd will appear the same when i click the button.
This is my ruby version:
ruby 2.3.3p222 (2016-11-21 revision 56859) [x64-mingw32]
And this issue will appear on the following ruby versions too, tested by me:
ruby 2.1.5p273 (2014-11-13 revision 48405) [x64-mingw32]
ruby 2.0.0p648 (2015-12-16) [x64-mingw32]
ruby 1.9.3p551 (2014-11-13) [i386-mingw32]
I tried to run the exe and to compile it on other pcs too, Windows 7 and 10. Still the same issue.
I solved by myself.
First, i required this in my script:
require 'win32ole'
Then i made a batch file, containing the command i need to be printed on a file, in this case ip config > info.txt
, and i named it run.bat
.
After this, I replaced system()
with the following:
WIN32OLE.new('Shell.Application').ShellExecute('run.bat','','','open',0)
This will work too:
WIN32OLE.new('WScript.Shell').Run("run.bat",0,0)
Here the documentation for win32ole
As first parameter i used the batch file i just created, and the last parameter, the 0, made the trick. It sets the new cmd window to be hided and so it wont ever pop up again.
I tried with rubyw efdsk.rb
and also to build an exe with ocra. No annoying windows popping up.