I'm a beginer of ruby, I want to know how to call external applications
in ruby, without the cmd window poping up.
I leanrt this link: http://www.ruby-forum.com/topic/213521#new, and
tried all the below ways:
result = `#{cmd}` #I tried this but the window still poped up
result = IO.popen("#{cmd}").read #and the same with this one
Process.create(
:app_name => cmd,
:startup_info=> {:sw_flags=>Process::SW_HIDE , :startf_flags =>
Process::STARTF_USESHOWWINDOW} ) #at last, I use process.create and the black window disappeared.
It worked good when I set cmd as "\"#{winrar_path}\\winrar.exe\" e -y
-o+ -ibck \"#{para[:dst_path]}\\*.zip\" \"#{para[:dst_path]}\\\"", but
when I changed it to "del *.zip", it always said "CreateProcess()
failed: ", as below:
The other problem is, if I use Process.create to unzip some file
firstly, and then use Process.create to do some other things to the
new-unzip files secondly, the second application sometimes failed, I
think maybe because the first unzip process is still processing? How to
avoid this? Thanks:)
You need a command line version tool like 7-zip (7za) that works in
the command line and can be hidden or look in WinRAR documentation
about silent command line extraction arguments.
···
On Nov 23, 12:08 am, Fengfeng Li <lifengf...@huawei.com> wrote:
Hi everyone,
I'm a beginer of ruby, I want to know how to call external applications
in ruby, without the cmd window poping up.
I leanrt this link:How to avoid black-windows using system()? - Ruby - Ruby-Forum, and
tried all the below ways:
result = `#{cmd}` #I tried this but the window still poped up
result = IO.popen("#{cmd}").read #and the same with this one
Process.create(
:app_name => cmd,
:startup_info=> {:sw_flags=>Process::SW_HIDE , :startf_flags =>
Process::STARTF_USESHOWWINDOW} ) #at last, I use process.create and the black window disappeared.
It worked good when I set cmd as "\"#{winrar_path}\\winrar.exe\" e -y
-o+ -ibck \"#{para[:dst_path]}\\*.zip\" \"#{para[:dst_path]}\\\"", but
when I changed it to "del *.zip", it always said "CreateProcess()
failed: ", as below:
If you want to force several processes to run sequentially then you should issue waitpid calls after launching each one so that they're only launched as the previous process is completed. A more elegant alternative would be to launch a single process which piped the output of each command into the next and let the OS work out the details for you, but that's dependent on the command you're running being pipe friendly.
Ellie
Eleanor McHugh
Games With Brains
···
On 23 Nov 2010, at 03:08, Fengfeng Li wrote:
The other problem is, if I use Process.create to unzip some file
firstly, and then use Process.create to do some other things to the
new-unzip files secondly, the second application sometimes failed, I
think maybe because the first unzip process is still processing? How to
avoid this? Thanks:)
:startup_info=> {:sw_flags=>Process::SW_HIDE , :startf_flags =>
Process::STARTF_USESHOWWINDOW} ) #at last, I use process.create and the black window disappeared.
It worked good when I set cmd as "\"#{winrar_path}\\winrar.exe\" e -y
-o+ -ibck \"#{para[:dst_path]}\\*.zip\" \"#{para[:dst_path]}\\\"", but
when I changed it to "del *.zip", it always said "CreateProcess()
failed: ", as below:
WinRAR will pop up a Windows during extraction.
You need a command line version tool like 7-zip (7za) that works in
the command line and can be hidden or look in WinRAR documentation
about silent command line extraction arguments.
Thanks for your reply. Maybe I didn't explain my problem clearly. My
problem is the process.create works fine with winrar, but when I change
the cmd as "del *.zip", it says "CreateProcess() failed", I wonder why
the "del *.zip" cann't work with process.create. as below:
If you want to force several processes to run sequentially then you
should issue waitpid calls after launching each one so that they're only
launched as the previous process is completed. A more elegant
alternative would be to launch a single process which piped the output
of each command into the next and let the OS work out the details for
you, but that's dependent on the command you're running being pipe
friendly.
Ellie
Eleanor McHugh
Games With Brains
----
raise ArgumentError unless @reality.responds_to? :reason
Easy test: Hast it been documented? Then it exists until the end of
time, Windows, or Microsoft, whichever comes first.
···
On Wed, Nov 24, 2010 at 9:54 AM, Arturo Garcia <arturo.g.arturo@gmail.com> wrote:
Is "del" is an actual executable? It used to be in old DOS but Mr. Windows
has a history of change....
--
Phillip Gawlowski
Though the folk I have met,
(Ah, how soon!) they forget
When I've moved on to some other place,
There may be one or two,
When I've played and passed through,
Who'll remember my song or my face.
Is "del" is an actual executable? It used to be in old DOS but Mr.
Windows
has a history of change....
I use fileUtils.chdir(dir) to change to a dir in which .zip files exist,
then I can use system("del *.zip") to del them, but Process.create()
will report an error. Maybe because fileUtils.chdir(dir) doesn't work
for Process.create()?
Is "del" is an actual executable? It used to be in old DOS but Mr.
Windows
has a history of change....
I use fileUtils.chdir(dir) to change to a dir in which .zip files exist,
then I can use system("del *.zip") to del them, but Process.create()
will report an error. Maybe because fileUtils.chdir(dir) doesn't work
for Process.create()?
Personally, I'd go with FileUtils.rm( Dir.glob('*.zip') ), just
because it is more portable, and doesn't incur the cost (negligible,
but still :P) of spinning off a new process. Additionally, I have to
deal only with Ruby's idiosyncrasies. No need to pile cmd.exe's
baggage on top of that.
···
On Thu, Nov 25, 2010 at 3:13 AM, Fengfeng Li <lifengfeng@huawei.com> wrote:
Thanks for your help, both 'cmd.exe /c del *.zip' and FileUtils.rm
Dir.glob('*.zip') can solve my problem^^
--
Phillip Gawlowski
Though the folk I have met,
(Ah, how soon!) they forget
When I've moved on to some other place,
There may be one or two,
When I've played and passed through,
Who'll remember my song or my face.
On 25 November 2010 09:45, Phillip Gawlowski <cmdjackryan@googlemail.com> wrote:
On Thu, Nov 25, 2010 at 3:13 AM, Fengfeng Li <lifengfeng@huawei.com> wrote:
Thanks for your help, both 'cmd.exe /c del *.zip' and FileUtils.rm
Dir.glob('*.zip') can solve my problem^^
Personally, I'd go with FileUtils.rm( Dir.glob('*.zip') ), just
because it is more portable, and doesn't incur the cost (negligible,
but still :P) of spinning off a new process. Additionally, I have to
deal only with Ruby's idiosyncrasies. No need to pile cmd.exe's
baggage on top of that.