win32-process 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,12 @@
1
+ = 0.6.4 - 13-Nov-2010
2
+ * Altered the wait, wait2, waitpid and waitpid2 methods to match the current
3
+ MRI interface, i.e. they accept and optional pid and flags, though the
4
+ latter is ignored. Thanks go to Robert Wahler for the spot.
5
+ * Renamed the example scripts to avoid any potential confusion with actual
6
+ test scripts and cleaned them up a bit.
7
+ * Added Rake tasks to run the example programs.
8
+ * Updated the MANIFEST.
9
+
1
10
  = 0.6.3 - 9-Nov-2010
2
11
  * Fixed a bug in the Process.kill method where the remote thread created
3
12
  was not being properly closed. Thanks go to Ben Nagy for the spot.
data/MANIFEST CHANGED
@@ -1,11 +1,11 @@
1
- * CHANGES
2
- * README
3
- * MANIFEST
4
- * Rakefile
5
- * win32-process.gemspec
6
- * examples/test_create.rb
7
- * examples/test_fork_wait.rb
8
- * examples/test_fork_waitpid.rb
9
- * examples/test_kill.rb
10
- * lib/win32/process.rb
11
- * test/tc_process.rb
1
+ * CHANGES
2
+ * README
3
+ * MANIFEST
4
+ * Rakefile
5
+ * win32-process.gemspec
6
+ * examples/example_create.rb
7
+ * examples/example_fork_wait.rb
8
+ * examples/example_fork_waitpid.rb
9
+ * examples/example_kill.rb
10
+ * lib/win32/process.rb
11
+ * test/test_process.rb
data/Rakefile CHANGED
@@ -20,6 +20,28 @@ namespace :gem do
20
20
  end
21
21
  end
22
22
 
23
+ namespace :example do
24
+ desc 'Run the fork + wait example'
25
+ task :fork_wait do
26
+ sh "ruby -Ilib examples/example_fork_wait.rb"
27
+ end
28
+
29
+ desc 'Run the fork + waitpid example'
30
+ task :fork_waitpid do
31
+ sh "ruby -Ilib examples/example_fork_waitpid.rb"
32
+ end
33
+
34
+ desc 'Run the kill example'
35
+ task :kill do
36
+ sh "ruby -Ilib examples/example_kill.rb"
37
+ end
38
+
39
+ desc 'Run the create example'
40
+ task :create do
41
+ sh "ruby -Ilib examples/example_create.rb"
42
+ end
43
+ end
44
+
23
45
  Rake::TestTask.new do |t|
24
46
  t.verbose = true
25
47
  t.warning = true
@@ -1,39 +1,35 @@
1
- ##########################################################################
2
- # test_create.rb
3
- #
4
- # Simple test program for the Process.create() method.
5
- ##########################################################################
6
- Dir.chdir('..') if File.basename(Dir.pwd) == 'examples'
7
- $LOAD_PATH.unshift Dir.pwd
8
- $LOAD_PATH.unshift Dir.pwd + '/lib'
9
- Dir.chdir('examples') rescue nil
10
-
11
- require "win32/process"
12
-
13
- p Process::WIN32_PROCESS_VERSION
14
-
15
- struct = Process.create(
16
- :app_name => "notepad.exe",
17
- :creation_flags => Process::DETACHED_PROCESS,
18
- :process_inherit => false,
19
- :thread_inherit => true,
20
- :cwd => "C:\\",
21
- :inherit => true,
22
- :environment => "SYSTEMROOT=#{ENV['SYSTEMROOT']};PATH=C:\\"
23
- )
24
-
25
- p struct
26
-
27
- =begin
28
- # Don't run this from an existing terminal
29
- pid = Process.create(
30
- :app_name => "cmd.exe",
31
- :creation_flags => Process::DETACHED_PROCESS,
32
- :startf_flags => Process::USEPOSITION,
33
- :x => 0,
34
- :y => 0,
35
- :title => "Hi Dan"
36
- )
37
-
38
- puts "Pid of new process: #{pid}"
39
- =end
1
+ ##########################################################################
2
+ # example_create.rb
3
+ #
4
+ # Simple test program for the Process.create() method. You can run this
5
+ # code via the 'example:create' task.
6
+ ##########################################################################
7
+ require "win32/process"
8
+
9
+ p Process::WIN32_PROCESS_VERSION
10
+
11
+ struct = Process.create(
12
+ :app_name => "notepad.exe",
13
+ :creation_flags => Process::DETACHED_PROCESS,
14
+ :process_inherit => false,
15
+ :thread_inherit => true,
16
+ :cwd => "C:\\",
17
+ :inherit => true,
18
+ :environment => "SYSTEMROOT=#{ENV['SYSTEMROOT']};PATH=C:\\"
19
+ )
20
+
21
+ p struct
22
+
23
+ =begin
24
+ # Don't run this from an existing terminal
25
+ pid = Process.create(
26
+ :app_name => "cmd.exe",
27
+ :creation_flags => Process::DETACHED_PROCESS,
28
+ :startf_flags => Process::USEPOSITION,
29
+ :x => 0,
30
+ :y => 0,
31
+ :title => "Hi Dan"
32
+ )
33
+
34
+ puts "Pid of new process: #{pid}"
35
+ =end
@@ -1,33 +1,29 @@
1
- ##########################################################################
2
- # test_fork_wait.rb
3
- #
4
- # Generic test script for futzing around with the block form of fork/wait
5
- ##########################################################################
6
- Dir.chdir('..') if File.basename(Dir.pwd) == 'examples'
7
- $LOAD_PATH.unshift Dir.pwd
8
- $LOAD_PATH.unshift Dir.pwd + '/lib'
9
- Dir.chdir('examples') rescue nil
10
-
11
- require 'win32/process'
12
-
13
- puts "VERSION: " + Process::WIN32_PROCESS_VERSION
14
-
15
- # In the child, using block form
16
- fork{
17
- 7.times { |i|
18
- puts "Child: #{i}"
19
- sleep 1
20
- }
21
- }
22
-
23
- # Back in the parent
24
- 4.times{ |i|
25
- puts "Parent: #{i}"
26
- sleep 1
27
- }
28
-
29
- # Wait for the children
30
- Process.wait
31
-
32
- # Children should be done here before continuing on
33
- puts "Continuing on..."
1
+ ##########################################################################
2
+ # example_fork_wait.rb
3
+ #
4
+ # Generic test script for futzing around with the block form of
5
+ # fork/wait. You can run this example via the 'example:fork_wait' task.
6
+ ##########################################################################
7
+ require 'win32/process'
8
+
9
+ puts "VERSION: " + Process::WIN32_PROCESS_VERSION
10
+
11
+ # In the child, using block form
12
+ fork{
13
+ 7.times { |i|
14
+ puts "Child: #{i}"
15
+ sleep 1
16
+ }
17
+ }
18
+
19
+ # Back in the parent
20
+ 4.times{ |i|
21
+ puts "Parent: #{i}"
22
+ sleep 1
23
+ }
24
+
25
+ # Wait for the children
26
+ Process.wait
27
+
28
+ # Children should be done here before continuing on
29
+ puts "Continuing on..."
@@ -1,50 +1,46 @@
1
- ##########################################################################
2
- # test_fork_waitpid.rb
3
- #
4
- # Generic test script for futzing around with the traditional form of
5
- # fork/wait, plus waitpid and waitpid2.
6
- ##########################################################################
7
- Dir.chdir('..') if File.basename(Dir.pwd) == 'examples'
8
- $LOAD_PATH.unshift Dir.pwd
9
- $LOAD_PATH.unshift Dir.pwd + '/lib'
10
- Dir.chdir('examples') rescue nil
11
-
12
- require 'win32/process'
13
-
14
- puts "VERSION: " + Process::WIN32_PROCESS_VERSION
15
-
16
- pid = Process.fork
17
- puts "PID1: #{pid}"
18
-
19
- #child
20
- if pid.nil?
21
- 7.times{ |i|
22
- puts "Child: #{i}"
23
- sleep 1
24
- }
25
- exit(-1)
26
- end
27
-
28
- pid2 = Process.fork
29
- puts "PID2: #{pid2}"
30
-
31
- #child2
32
- if pid2.nil?
33
- 7.times{ |i|
34
- puts "Child2: #{i}"
35
- sleep 1
36
- }
37
- exit(1)
38
- end
39
-
40
- #parent
41
- 2.times { |i|
42
- puts "Parent: #{i}"
43
- sleep 1
44
- }
45
-
46
- p Process.waitpid2(pid)
47
- p Process.waitpid2(pid2)
48
-
49
- puts "Continuing on..."
50
-
1
+ ##########################################################################
2
+ # example_fork_waitpid.rb
3
+ #
4
+ # Generic test script for futzing around with the traditional form of
5
+ # fork/wait, plus waitpid and waitpid2.
6
+ #
7
+ # You can run this code via the 'example:fork_waitpid' task.
8
+ ##########################################################################
9
+ require 'win32/process'
10
+
11
+ puts "VERSION: " + Process::WIN32_PROCESS_VERSION
12
+
13
+ pid = Process.fork
14
+ puts "PID1: #{pid}"
15
+
16
+ #child
17
+ if pid.nil?
18
+ 7.times{ |i|
19
+ puts "Child: #{i}"
20
+ sleep 1
21
+ }
22
+ exit(-1)
23
+ end
24
+
25
+ pid2 = Process.fork
26
+ puts "PID2: #{pid2}"
27
+
28
+ #child2
29
+ if pid2.nil?
30
+ 7.times{ |i|
31
+ puts "Child2: #{i}"
32
+ sleep 1
33
+ }
34
+ exit(1)
35
+ end
36
+
37
+ #parent
38
+ 2.times { |i|
39
+ puts "Parent: #{i}"
40
+ sleep 1
41
+ }
42
+
43
+ p Process.waitpid2(pid)
44
+ p Process.waitpid2(pid2)
45
+
46
+ puts "Continuing on..."
@@ -0,0 +1,34 @@
1
+ ##########################################################################
2
+ # example_kill.rb
3
+ #
4
+ # Generic test script for futzing around Process.kill. This script
5
+ # requires the sys-proctable library.
6
+ #
7
+ # You can run this example via the 'example:kill' task.
8
+ ##########################################################################
9
+ require "win32/process"
10
+
11
+ begin
12
+ require "sys/proctable"
13
+ rescue LoadError
14
+ STDERR.puts "Whoa there!"
15
+ STDERR.puts "This script requires the sys-proctable package to work."
16
+ STDERR.puts "You can find it at http://ruby-sysutils.sf.net"
17
+ STDERR.puts "Exiting..."
18
+ exit
19
+ end
20
+
21
+ include Sys
22
+
23
+ puts "VERSION: " + Process::WIN32_PROCESS_VERSION
24
+
25
+ IO.popen("notepad")
26
+ sleep 1 # Give it a chance to start before checking for its pid
27
+
28
+ pids = []
29
+
30
+ ProcTable.ps{ |s|
31
+ pids.push(s.pid) if s.cmdline =~ /notepad/i
32
+ }
33
+
34
+ p Process.kill(9,pids.last)
@@ -21,7 +21,7 @@ module Process
21
21
  undef_method :setpriority, :wait, :wait2, :waitpid, :waitpid2, :uid
22
22
 
23
23
  # The version of the win32-process library
24
- WIN32_PROCESS_VERSION = '0.6.3'
24
+ WIN32_PROCESS_VERSION = '0.6.4'
25
25
 
26
26
  include Windows::Process
27
27
  include Windows::Thread
@@ -424,10 +424,13 @@ module Process
424
424
 
425
425
  # Waits for the given child process to exit and returns that pid.
426
426
  #
427
+ # The +flags+ argument is ignored at the moment. It is provided strictly
428
+ # for interface compatibility.
429
+ #
427
430
  # Note that the $? (Process::Status) global variable is NOT set. This
428
431
  # may be addressed in a future release.
429
432
  #
430
- def waitpid(pid)
433
+ def waitpid(pid, flags = nil)
431
434
  exit_code = [0].pack('L')
432
435
  handle = OpenProcess(PROCESS_ALL_ACCESS, 0, pid)
433
436
 
@@ -456,6 +459,9 @@ module Process
456
459
 
457
460
  # Waits for the given child process to exit and returns an array containing
458
461
  # the process id and the exit status.
462
+ #
463
+ # The +flags+ argument is ignored at the moment. It is provided strictly
464
+ # for interface compatibility.
459
465
  #
460
466
  # Note that the $? (Process::Status) global variable is NOT set. This
461
467
  # may be addressed in a future release if/when possible.
@@ -463,7 +469,7 @@ module Process
463
469
  # Ruby does not provide a way to hook into $? so there's no way for us
464
470
  # to set it.
465
471
  #
466
- def waitpid2(pid)
472
+ def waitpid2(pid, flags = nil)
467
473
  exit_code = [0].pack('L')
468
474
  handle = OpenProcess(PROCESS_ALL_ACCESS, 0, pid)
469
475
 
@@ -877,7 +883,11 @@ module Process
877
883
  end
878
884
 
879
885
  # Waits for any child process to exit and returns the process id of that
880
- # child.
886
+ # child. If a pid is provided that is greater than or equal to 0, then
887
+ # it is the equivalent of calling Process.waitpid.
888
+ #
889
+ # The +flags+ argument is ignored at the moment. It is provided strictly
890
+ # for interface compatibility.
881
891
  #
882
892
  # Note that the $? (Process::Status) global variable is NOT set. This
883
893
  # may be addressed in a future release.
@@ -885,7 +895,12 @@ module Process
885
895
  # The GetProcessId() function is not defined in Windows 2000 or earlier
886
896
  # so we have to do some extra work for those platforms.
887
897
  #
888
- def wait
898
+ def wait(pid = -1, flags = nil)
899
+ if pid && pid >= 0
900
+ pid, status = waitpid(pid, flags)
901
+ return pid
902
+ end
903
+
889
904
  handles = []
890
905
 
891
906
  # Windows 2000 or earlier
@@ -933,6 +948,9 @@ module Process
933
948
 
934
949
  # Waits for any child process to exit and returns an array containing the
935
950
  # process id and the exit status of that child.
951
+ #
952
+ # The +flags+ argument is ignored at the moment. It is provided strictly
953
+ # for interface compatibility.
936
954
  #
937
955
  # Note that the $? (Process::Status) global variable is NOT set. This
938
956
  # may be addressed in a future release.
@@ -940,7 +958,12 @@ module Process
940
958
  # The GetProcessId() function is not defined in Windows 2000 or earlier
941
959
  # so we have to do some extra work for those platforms.
942
960
  #
943
- def wait2
961
+ def wait2(pid = -1, flags = nil)
962
+ if pid && pid >= 0
963
+ pid, status = waitpid2(pid, flags)
964
+ return pid
965
+ end
966
+
944
967
  handles = []
945
968
 
946
969
  # Windows 2000 or earlier
@@ -41,7 +41,7 @@ class TC_Win32Process < Test::Unit::TestCase
41
41
  end
42
42
 
43
43
  def test_version
44
- assert_equal('0.6.3', Process::WIN32_PROCESS_VERSION)
44
+ assert_equal('0.6.4', Process::WIN32_PROCESS_VERSION)
45
45
  end
46
46
 
47
47
  def test_kill
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'win32-process'
5
- spec.version = '0.6.3'
5
+ spec.version = '0.6.4'
6
6
  spec.license = 'Artistic 2.0'
7
7
  spec.authors = ['Daniel Berger', 'Park Heesob']
8
8
  spec.email = 'djberg96@gmail.com'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: win32-process
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 3
10
- version: 0.6.3
9
+ - 4
10
+ version: 0.6.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Daniel Berger
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-11-09 00:00:00 -07:00
19
+ date: 2010-11-13 00:00:00 -07:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -77,10 +77,10 @@ extra_rdoc_files:
77
77
  - MANIFEST
78
78
  files:
79
79
  - CHANGES
80
- - examples/test_create.rb
81
- - examples/test_fork_wait.rb
82
- - examples/test_fork_waitpid.rb
83
- - examples/test_kill.rb
80
+ - examples/example_create.rb
81
+ - examples/example_fork_wait.rb
82
+ - examples/example_fork_waitpid.rb
83
+ - examples/example_kill.rb
84
84
  - lib/win32/process.rb
85
85
  - MANIFEST
86
86
  - Rakefile
@@ -1,35 +0,0 @@
1
- ##########################################################################
2
- # test_kill.rb
3
- #
4
- # Generic test script for futzing around Process.kill. This script
5
- # requires the sys-proctable package (available on the RAA).
6
- ##########################################################################
7
- Dir.chdir('..') if File.basename(Dir.pwd) == 'examples'
8
- $LOAD_PATH.unshift Dir.pwd
9
- $LOAD_PATH.unshift Dir.pwd + '/lib'
10
- Dir.chdir('examples') rescue nil
11
-
12
- require "win32/process"
13
-
14
- begin
15
- require "sys/proctable"
16
- rescue LoadError
17
- STDERR.puts "Whoa there!"
18
- STDERR.puts "This script requires the sys-proctable package to work."
19
- STDERR.puts "You can find it at http://ruby-sysutils.sf.net"
20
- STDERR.puts "Exiting..."
21
- exit
22
- end
23
- include Sys
24
-
25
- puts "VERSION: " + Process::WIN32_PROCESS_VERSION
26
-
27
- IO.popen("notepad")
28
- sleep 1 # Give it a chance to start before checking for its pid
29
-
30
- pids = []
31
- ProcTable.ps{ |s|
32
- pids.push(s.pid) if s.cmdline =~ /notepad/i
33
- }
34
-
35
- p Process.kill(9,pids.last)