How to avoid black-windows using system() ?

R

Rémi Cools

Hi,

I'm just discovering Ruby, so, be indulgent!

When I use this code :

cmd = "d:\\mes documents\\___3D\\imageMagick\\montage.exe"
system( [cmd, cmd], "-background", "#000000", "-geometry", "100%%",
"1.jpg", "2.jpg", "3.jpg")

A black-window like the jpg in attachment opens itself for half a
second.

Due to an iteration, this black-window opens itself dozen of times!

It's not very professional.

Is there a way to avoid that with Ruby ?
Or must I absolutely look for that with the called-program ? (sort of
silent mode)


Thanks

Regards.

Attachments:
http://www.ruby-forum.com/attachment/4873/BLACK.jpg
 
R

Roger Pack

Rémi Cools said:
Hi,

I'm just discovering Ruby, so, be indulgent!

When I use this code :

cmd = "d:\\mes documents\\___3D\\imageMagick\\montage.exe"
system( [cmd, cmd], "-background", "#000000", "-geometry", "100%%",
"1.jpg", "2.jpg", "3.jpg")

A black-window like the jpg in attachment opens itself for half a
second.

Due to an iteration, this black-window opens itself dozen of times!

It's not very professional.

Is there a way to avoid that with Ruby ?

If you run it from ruby within a command prompt it seems to work.
Also appears if you use IO.popen it also works.
 
R

Rémi Cools

Hi Clifford Heath & Roger Pack,

thanks for you answers.

I don't understand wath you say, perhaps I didn't explain my problem
correctly.

I want to avoid that system() call cmd.exe

in :
system( [cmd, cmd], "-background", "#000000", "-geometry", "100%%"
cmd is a String :
cmd = "d:\\mes documents\\___3D\\imageMagick\\montage.exe"
not the cmd.exe shell

I thought that when you call system() with only one parameter, cmd.exe
is used but when you call system() with more than one parameter, the
program is directly launched without cmd.exe

Can you confirm that ?

thanks & regards.
 
C

Clifford Heath

Roger said:
system( [cmd, cmd], "-background", "#000000", "-geometry", "100%%",
"1.jpg", "2.jpg", "3.jpg")
A black-window like the jpg in attachment opens itself for half a
second.

system uses cmd to run the command, and cmd launches a virtual-DOS
environment. It's possible (but not from Ruby, I think) to launch
cmd with no window - my team figured out how some years back - but
I'd have to search to get the details.

The only way I can think of is to change the SHELL environment
variable to designate a wrapper for cmd that sets the "no-window"
option.

Sorry it's not a solution, but I thought the pointer might help.

Clifford Heath.
 
L

Luis Lavena

Hi Clifford Heath & Roger Pack,

thanks for you answers.

I don't understand wath you say, perhaps I didn't explain my problem
correctly.

I want to avoid that system() call cmd.exe

in :
    system( [cmd, cmd], "-background", "#000000", "-geometry", "100%%"
cmd is a String :
    cmd = "d:\\mes documents\\___3D\\imageMagick\\montage.exe"
not the cmd.exe shell

I thought that when you call system() with only one parameter, cmd.exe
is used but when you call system() with more than one parameter, the
program is directly launched without cmd.exe

Can you confirm that ?

That is default behavior of system. Two things:

If you want to avoid the cmd.exe black screen from appearing, you can
use backticks:

result = `#{cmd}`

system() with multiple parameters has some weird behaviors on Windows,
it requires the absolute path to the executable as first argument.

system() differs behavior between 1.8 and 1.9, the later works better.

HTH,
 
R

Ralph Shnelvar

Rémi,


Thursday, July 22, 2010, 3:37:50 AM, you wrote:

RC> Hi Clifford Heath & Roger Pack,

RC> thanks for you answers.

RC> I don't understand wath you say, perhaps I didn't explain my problem
RC> correctly.

RC> I want to avoid that system() call cmd.exe

RC> in :
RC> system( [cmd, cmd], "-background", "#000000", "-geometry", "100%%"
RC> cmd is a String :
RC> cmd = "d:\\mes documents\\___3D\\imageMagick\\montage.exe"
RC> not the cmd.exe shell

RC> I thought that when you call system() with only one parameter, cmd.exe
RC> is used but when you call system() with more than one parameter, the
RC> program is directly launched without cmd.exe

RC> Can you confirm that ?

RC> thanks & regards.

I'm not sure I follow you ...

Have you tried the "back tick" processing to do what you want?
`d:/mes documents/___3D/imageMagick/montage.exe`
 
R

Roger Pack

RC> I thought that when you call system() with only one parameter,
cmd.exe
RC> is used but when you call system() with more than one parameter, the
RC> program is directly launched without cmd.exe

RC> Can you confirm that ?


I think I know where the confusion lies.
from [1] it reads

" If exec is given a single argument, that argument is taken as a line
that is subject to shell expansion before being executed. If multiple
arguments are given, the second and subsequent arguments are passed as
parameters to command with no shell expansion"

The shell expansion it is referring to here is things like expanding
paths, ex:
system("ls $HOME") gets expanded to system("ls /home/username")

however

system("ls", "$HOME")

does not get auto-expanded.

They both require "sub-shell" in windows because the process you are
executing (montage.exe) requires somewhere to output its data to, so it
pops up. It is possible to make a program "not require an output shell"
but most programs aren't setup that way (rubyw.exe is, ruby.exe isn't,
for example).

Recommendation: use IO.popen("whatever").read to avoid popping it up.
GL.
-r



[1] http://ruby-doc.org/core/classes/Kernel.html#M005968
 
A

adam hegge

[Note: parts of this message were removed to make it a legal post.]

require 'win32/process'
Process.create({:app_name => cmd, :startup_info=>
{:sw_flags=>Process::SW_HIDE , :startf_flags =>
Process::STARTF_USESHOWWINDOW}})

RC> I thought that when you call system() with only one parameter,
cmd.exe
RC> is used but when you call system() with more than one parameter, the
RC> program is directly launched without cmd.exe

RC> Can you confirm that ?


I think I know where the confusion lies.
from [1] it reads

" If exec is given a single argument, that argument is taken as a line
that is subject to shell expansion before being executed. If multiple
arguments are given, the second and subsequent arguments are passed as
parameters to command with no shell expansion"

The shell expansion it is referring to here is things like expanding
paths, ex:
system("ls $HOME") gets expanded to system("ls /home/username")

however

system("ls", "$HOME")

does not get auto-expanded.

They both require "sub-shell" in windows because the process you are
executing (montage.exe) requires somewhere to output its data to, so it
pops up. It is possible to make a program "not require an output shell"
but most programs aren't setup that way (rubyw.exe is, ruby.exe isn't,
for example).

Recommendation: use IO.popen("whatever").read to avoid popping it up.
GL.
-r



[1] http://ruby-doc.org/core/classes/Kernel.html#M005968
RC> thanks & regards.

I'm not sure I follow you ...

Have you tried the "back tick" processing to do what you want?
`d:/mes documents/___3D/imageMagick/montage.exe`
 
R

Roger Pack

I think 1.9's Process.spawn also works for this, since it inherits
parent stderr and stdout by default, AFAIK.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top