[Title] Fixed a but that "log wraaper" process does not work on windows
authordonghee yang <donghee.yang@samsung.com>
Sat, 22 Sep 2012 01:23:46 +0000 (10:23 +0900)
committerdonghee yang <donghee.yang@samsung.com>
Sat, 22 Sep 2012 01:23:46 +0000 (10:23 +0900)
src/common/execute_with_log [deleted file]
src/common/execute_with_log.rb [new file with mode: 0755]
src/common/utils.rb

diff --git a/src/common/execute_with_log b/src/common/execute_with_log
deleted file mode 100755 (executable)
index 3a0bddd..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-#!/usr/bin/ruby
-
-require 'logger'
-
-# parse arguments
-cmd = ARGV[0]
-log_path = ARGV[1]
-
-# if log path specified, generate log
-if not log_path.nil? then
-       # create logger
-       log = Logger.new(log_path)
-
-       # execute and write log
-       IO.popen("#{cmd} 2>&1") { |io|
-               io.each { |line|
-               log.info line
-               }
-       }
-
-       # return exit code
-       exit $?.exitstatus
-#$?.to_i
-else
-       # execute command & wait
-       pipe = IO.popen("#{cmd}")
-       pid, status = Process.waitpid2(pipe.pid)
-
-       # return exit code
-       if pid.nil? or status.nil? then
-               exit 1
-       else
-               exit status.exitstatus
-       end
-end
diff --git a/src/common/execute_with_log.rb b/src/common/execute_with_log.rb
new file mode 100755 (executable)
index 0000000..7990697
--- /dev/null
@@ -0,0 +1,52 @@
+#!/usr/bin/ruby
+=begin
+ execute_with_log.rb 
+
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+Contact:
+Taejun Ha <taejun.ha@samsung.com>
+Jiil Hyoun <jiil.hyoun@samsung.com>
+Donghyuk Yang <donghyuk.yang@samsung.com>
+DongHee Yang <donghee.yang@samsung.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+- S-Core Co., Ltd
+=end
+
+require 'logger'
+$LOAD_PATH.unshift File.dirname(__FILE__)
+require 'utils.rb'
+
+# parse arguments
+cmd = ARGV[0]
+log_path = ARGV[1]
+
+# create logger
+log = Logger.new(log_path)
+
+# generate command
+cmd = Utils.generate_shell_command(cmd, nil)
+
+# execute and write log
+IO.popen("#{cmd} 2>&1") { |io|
+       io.each { |line|
+               log.info line
+       }
+}
+
+# return exit code
+exit $?.exitstatus
index 70ee2ad160391b7142c093c24ada2603504f32ab..ae5ec28bd94d4254b032fc8944e34f97b179af56 100644 (file)
@@ -25,6 +25,7 @@ limitations under the License.
 Contributors:
 - S-Core Co., Ltd
 =end
+require 'rbconfig'
 
 class Utils
        STARTUP_INFO_SIZE = 68
@@ -198,32 +199,24 @@ class Utils
        # can decide whether wait or not
        def Utils.execute_shell_with_log(cmd, log_path, wait=true)
 
-               if get_os_category( HOST_OS ) != "windows" then
-                       # call execute
-                       cmd = "'#{File.dirname(__FILE__)}/execute_with_log' '#{cmd}' '#{log_path}'"
+               ruby_path=File.join(Config::CONFIG["bindir"],
+                                  Config::CONFIG["RUBY_INSTALL_NAME"] +
+                                  Config::CONFIG["EXEEXT"])
 
-                       # generate command
-                       cmd = generate_shell_command(cmd, nil)
-
-                       # print log
-                       pipe = IO.popen("#{cmd} 2>&1")
-                       if wait then
-                               return Process.waitpid2(pipe.pid)
-                       else
-                               return [pipe.pid,nil]
-                       end
-               else
-                       # create logger
-                       log = Logger.new(log_path)
+               # call execute
+               os_category = get_os_category( HOST_OS )
+               if os_category == "windows" then
+                       cmd = cmd.gsub("\"", "\\\"")
+               end
 
-                       IO.popen("#{cmd} 2>&1") { |io|
-                               io.each { |line|
-                               log.info line
-                               }
-                       }
+               cmd = "#{ruby_path} \"#{File.expand_path(File.dirname(__FILE__))}/execute_with_log.rb\" \"#{cmd}\" \"#{log_path}\""
 
-                       # return exit code
-                       return [nil, $?]
+               # print log
+               pipe = IO.popen("#{cmd} 2>&1")
+               if wait then
+                       return Process.waitpid2(pipe.pid)
+               else
+                       return [pipe.pid,nil]
                end
        end