process_starter 1.0.10 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README CHANGED
@@ -15,12 +15,12 @@ ProcessStarter.allowed_methods = [:psexec,:start,:spawn,:fork]
15
15
  specify which methods are allowed to start the process. So we have psexec
16
16
  (if found on the target machine) and 'cmd /c start ...' for windows,
17
17
  and spawn (if in ruby 1.9) or fork in linux. This is the default,
18
- but you can redefine it, for example
18
+ but you can redefine it, for example:
19
19
  ProcessStarter.allowed_methods = [:start,:fork]
20
20
 
21
21
  Also you can set allowed methods in command call:
22
22
 
23
- ProcessStarter.start("somecmd arg1 arg2",[:start,:fork])
23
+ ProcessStarter.start("somecmd arg1 arg2", [:start,:fork] )
24
24
 
25
25
  This overrides ProcessStarter.allowed_methods values.
26
26
 
@@ -30,8 +30,12 @@ module ProcessStarter
30
30
  # works in windows and linux
31
31
  def self.start(s, allowed_methods = nil )
32
32
  allowed_methods ||= self.allowed_methods
33
+
33
34
  log "********* ProcessStarter.start INVOKING EXTERNAL COMMAND #{s}, WINRUN IS #{WINRUN}, HAVE_POSIX_SPAWN IS #{HAVE_POSIX_SPAWN}, HAVE_SPAWN is #{HAVE_SPAWN}, allowed_methods are #{allowed_methods.inspect}"
34
35
  if WINRUN
36
+ # if s.index("'")
37
+ # s = s.gsub("'","\\'")
38
+ # end
35
39
  @@have_psexec ||= allowed_methods.include?(:psexec) ? ((`psexec /?` rescue "") =~ /computer/ ? 2 : 1) : -1
36
40
  if @@have_psexec == 2 and allowed_methods.include?(:psexec)
37
41
  log "starting using psexec"
@@ -40,10 +44,29 @@ module ProcessStarter
40
44
  r = system("psexec -d -w #{Dir.pwd} #{s}")
41
45
  else
42
46
  log "starting using START cmd /c (inherits descriptors (?) - bad)"
43
- system("start cmd /c #{s}")
47
+ close_io(true)
48
+ system("start /b cmd /c #{s}")
44
49
  end
45
50
  else
46
51
  log "Executing in Linux style"
52
+
53
+ # fix "s" for stdin, stdout, stderr
54
+ nilport = WINRUN ? "NUL" : "nil"
55
+ # not specified stdin?
56
+ if not s =~ /</
57
+ s = s + " <#{nilport}"
58
+ end
59
+ # not specified both stdout and stderr?
60
+ if not s =~ />/
61
+ s = s + " >#{nilport} 2>#{nilport}"
62
+ end
63
+ # not specified stderr?
64
+ if not s =~ /2>/
65
+ s = s + " 2>#{nilport}"
66
+ end
67
+ # we omit the case: "program 2>nil", which specifies that stdout is not redirected, which means that
68
+ # if user specify 2>, he is clever, and has to specify 1> too.
69
+
47
70
  if HAVE_POSIX_SPAWN and allowed_methods.include?(:posix_spawn)
48
71
  close_them = Hash[ close_io().map {|x| [x, :close]} ]
49
72
  log "POSIX::Spawn::spawn with close descriptors: #{close_them.inspect}"
data/test/test2child.arb CHANGED
@@ -1,4 +1,5 @@
1
1
  puts "im a child"
2
+
2
3
  #require File.join( File.expand_path(File.dirname(__FILE__)), "..","lib","process_starter.rb" )
3
4
  #d = ProcessStarter.close_io()
4
5
  #puts "im a child and my descriptors: #{d.inspect}"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: process_starter
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 10
10
- version: 1.0.10
9
+ - 11
10
+ version: 1.0.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pavel Vasev
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-10-18 00:00:00 Z
18
+ date: 2012-02-22 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: A gem for Ruby 1.8 to start process in parallel, 1) don't wait for it finish 2) dont inherit io file handles 3) both in windows/linux. Ruby 1.9 dont need it because it has spawn method.