Win32OperatingSystem.st
changeset 20930 793c81da8cb1
parent 20897 49ffdb7d9c18
child 20966 283c240f38d1
equal deleted inserted replaced
20929:a60bc618b504 20930:793c81da8cb1
   901     ]
   901     ]
   902 								[exBegin]
   902 								[exBegin]
   903 "
   903 "
   904 ! !
   904 ! !
   905 
   905 
   906 !Win32OperatingSystem class methodsFor:'debugging'!
       
   907 
       
   908 verbose:aBoolean
       
   909 %{
       
   910 #ifdef PROCESSDEBUGWIN32
       
   911     flag_PROCESSDEBUGWIN32 = (aBoolean == true);
       
   912 #endif
       
   913 %}
       
   914 ! !
       
   915 
       
   916 !Win32OperatingSystem class methodsFor:'initialization'!
   906 !Win32OperatingSystem class methodsFor:'initialization'!
   917 
   907 
   918 coInitialize
   908 coInitialize
   919 %{
   909 %{
   920     HRESULT hres;
   910     HRESULT hres;
  1719 
  1709 
  1720 setClipboardData: aCfConstant hMem: aMemHandle
  1710 setClipboardData: aCfConstant hMem: aMemHandle
  1721     |result|
  1711     |result|
  1722     result := self primSetClipboardData: aCfConstant hMem: aMemHandle address.
  1712     result := self primSetClipboardData: aCfConstant hMem: aMemHandle address.
  1723     result = 0 ifTrue: [ ^self error ].
  1713     result = 0 ifTrue: [ ^self error ].
       
  1714 ! !
       
  1715 
       
  1716 !Win32OperatingSystem class methodsFor:'debugging'!
       
  1717 
       
  1718 verbose:aBoolean
       
  1719 %{
       
  1720 #ifdef PROCESSDEBUGWIN32
       
  1721     flag_PROCESSDEBUGWIN32 = (aBoolean == true);
       
  1722 #endif
       
  1723 %}
  1724 ! !
  1724 ! !
  1725 
  1725 
  1726 !Win32OperatingSystem class methodsFor:'directory access'!
  1726 !Win32OperatingSystem class methodsFor:'directory access'!
  1727 
  1727 
  1728 linkInfoFor:osPathname fileSize:fileSize fileAttributes:osFileAttributes osCrtTime:osCrtTime osAccTime:osAccTime osModTime:osModTime
  1728 linkInfoFor:osPathname fileSize:fileSize fileAttributes:osFileAttributes osCrtTime:osCrtTime osAccTime:osAccTime osModTime:osModTime
  4337 !
  4337 !
  4338 
  4338 
  4339 startProcess:aCommandString inputFrom:anExternalInStream outputTo:anExternalOutStream
  4339 startProcess:aCommandString inputFrom:anExternalInStream outputTo:anExternalOutStream
  4340     errorTo:anExternalErrStream auxFrom:anAuxiliaryStream
  4340     errorTo:anExternalErrStream auxFrom:anAuxiliaryStream
  4341     environment:anEvironmentDictionary inDirectory:dir
  4341     environment:anEvironmentDictionary inDirectory:dir
  4342     showWindow:showWindowBooleanOrNil
  4342     newPgrp:newPgrp showWindow:showWindowBooleanOrNil
  4343 
  4343 
  4344     "start executing the OS command as specified by the argument, aCommandString
  4344     "start executing the OS command as specified by the argument, aCommandString
  4345      as a separate process; do not wait for the command to finish.
  4345      as a separate process; do not wait for the command to finish.
  4346      If aCommandString is a String, the commandString is passed to a shell for execution
  4346      If aCommandString is a String, the commandString is passed to a shell for execution
  4347      - see the description of 'sh -c' in your UNIX manual ('cmd.com' in your MSDOS manual).
  4347      - see the description of 'sh -c' in your UNIX manual ('cmd.com' in your MSDOS manual).
  4359 
  4359 
  4360     aCommandString isNil ifTrue:[^ nil].
  4360     aCommandString isNil ifTrue:[^ nil].
  4361     shellAndArgs := self commandAndArgsForOSCommand:aCommandString.
  4361     shellAndArgs := self commandAndArgsForOSCommand:aCommandString.
  4362 
  4362 
  4363     (in := anExternalInStream) isNil ifTrue:[
  4363     (in := anExternalInStream) isNil ifTrue:[
  4364 	nullStream := Filename nullDevice readWriteStream.
  4364         nullStream := Filename nullDevice readWriteStream.
  4365 	in := nullStream.
  4365         in := nullStream.
  4366     ].
  4366     ].
  4367     (out := anExternalOutStream) isNil ifTrue:[
  4367     (out := anExternalOutStream) isNil ifTrue:[
  4368 	nullStream isNil ifTrue:[nullStream := Filename nullDevice writeStream].
  4368         nullStream isNil ifTrue:[nullStream := Filename nullDevice writeStream].
  4369 	out := nullStream.
  4369         out := nullStream.
  4370     ].
  4370     ].
  4371     (err := anExternalErrStream) isNil ifTrue:[
  4371     (err := anExternalErrStream) isNil ifTrue:[
  4372 	err := out
  4372         err := out
  4373     ].
  4373     ].
  4374 
  4374 
  4375     rslt := self
  4375     rslt := self
  4376 	exec:(shellAndArgs at:1)
  4376         exec:(shellAndArgs at:1)
  4377 	withArguments:(shellAndArgs at:2)
  4377         withArguments:(shellAndArgs at:2)
  4378 	environment:anEvironmentDictionary
  4378         environment:anEvironmentDictionary
  4379 	fileDescriptors:(Array with:in fileHandle
  4379         fileDescriptors:(Array with:in fileHandle
  4380 			       with:out fileHandle
  4380                                with:out fileHandle
  4381 			       with:err fileHandle
  4381                                with:err fileHandle
  4382 			       with:(anAuxiliaryStream notNil ifTrue:[anAuxiliaryStream fileHandle] ifFalse:[nil]))
  4382                                with:(anAuxiliaryStream notNil ifTrue:[anAuxiliaryStream fileHandle] ifFalse:[nil]))
  4383 	fork:true
  4383         fork:true
  4384 	newPgrp:true
  4384         newPgrp:true
  4385 	inDirectory:dir
  4385         inDirectory:dir
  4386 	showWindow:(showWindowBooleanOrNil ? (shellAndArgs at:3)).
  4386         showWindow:(showWindowBooleanOrNil ? (shellAndArgs at:3)).
  4387 
  4387 
  4388     nullStream notNil ifTrue:[
  4388     nullStream notNil ifTrue:[
  4389 	nullStream close.
  4389         nullStream close.
  4390     ].
  4390     ].
  4391     ^ rslt
  4391     ^ rslt
  4392 
  4392 
  4393     "blocking at current prio (i.e. only higher prio threads execute):
  4393     "blocking at current prio (i.e. only higher prio threads execute):
  4394 
  4394 
  4410      pid := OperatingSystem startProcess:'sleep 10; grep drw' inputFrom:in outputTo:out errorTo:err.
  4410      pid := OperatingSystem startProcess:'sleep 10; grep drw' inputFrom:in outputTo:out errorTo:err.
  4411 
  4411 
  4412      The following will no longer work. monitorPid has disappeared
  4412      The following will no longer work. monitorPid has disappeared
  4413 
  4413 
  4414      pid notNil ifTrue:[
  4414      pid notNil ifTrue:[
  4415 	 Processor monitorPid:pid action:[:OSstatus | sema signal ].
  4415          Processor monitorPid:pid action:[:OSstatus | sema signal ].
  4416      ].
  4416      ].
  4417      in close.
  4417      in close.
  4418      out close.
  4418      out close.
  4419      err close.
  4419      err close.
  4420      sema wait.
  4420      sema wait.
  4425      |pid sema|
  4425      |pid sema|
  4426 
  4426 
  4427      sema := Semaphore new.
  4427      sema := Semaphore new.
  4428 
  4428 
  4429      Processor
  4429      Processor
  4430 	    monitor:[
  4430             monitor:[
  4431 		pid := OperatingSystem startProcess:'dir > out 2>err'
  4431                 pid := OperatingSystem startProcess:'dir > out 2>err'
  4432 	    ]
  4432             ]
  4433 	    action:[:osStatus | sema signal ].
  4433             action:[:osStatus | sema signal ].
  4434 
  4434 
  4435      sema wait.
  4435      sema wait.
  4436      Transcript showCR:'finished'
  4436      Transcript showCR:'finished'
  4437     "
  4437     "
  4438 
  4438 
  4440      |pid sema|
  4440      |pid sema|
  4441 
  4441 
  4442      sema := Semaphore new.
  4442      sema := Semaphore new.
  4443 
  4443 
  4444      Processor
  4444      Processor
  4445 	    monitor:[
  4445             monitor:[
  4446 		pid := OperatingSystem startProcess:'(echo 1 & stx --eval "Delay waitForSeconds:100" & dir) >out' withCRs
  4446                 pid := OperatingSystem startProcess:'(echo 1 & stx --eval "Delay waitForSeconds:100" & dir) >out' withCRs
  4447 	    ]
  4447             ]
  4448 	    action:[:osStatus | sema signal ].
  4448             action:[:osStatus | sema signal ].
  4449 
  4449 
  4450      Delay waitForSeconds:5.
  4450      Delay waitForSeconds:5.
  4451      OperatingSystem terminateProcessGroup:pid.
  4451      OperatingSystem terminateProcessGroup:pid.
  4452      Transcript showCR:'terminated'
  4452      Transcript showCR:'terminated'
  4453 END"
  4453 END"
  4456      |pid sema|
  4456      |pid sema|
  4457 
  4457 
  4458      sema := Semaphore new.
  4458      sema := Semaphore new.
  4459 
  4459 
  4460      Processor
  4460      Processor
  4461 	    monitor:[
  4461             monitor:[
  4462 		pid := OperatingSystem startProcess:{ 'C:\Users\cg\work\stx\projects\smalltalk\stx.com' . '--eval' . '"Delay waitForSeconds:100"' }
  4462                 pid := OperatingSystem startProcess:{ 'C:\Users\cg\work\stx\projects\smalltalk\stx.com' . '--eval' . '"Delay waitForSeconds:100"' }
  4463 	    ]
  4463             ]
  4464 	    action:[:osStatus | sema signal ].
  4464             action:[:osStatus | sema signal ].
  4465 
  4465 
  4466      Delay waitForSeconds:5.
  4466      Delay waitForSeconds:5.
  4467      OperatingSystem terminateProcess:pid.
  4467      OperatingSystem terminateProcess:pid.
  4468      Transcript showCR:'terminated'
  4468      Transcript showCR:'terminated'
  4469 END"
  4469 END"
  4470 
  4470 
  4471     "Modified: / 21-03-1997 / 10:04:35 / dq"
  4471     "Created: / 08-11-2016 / 21:23:17 / cg"
  4472     "Modified: / 15-07-1997 / 16:03:51 / stefan"
       
  4473     "Created: / 12-11-1998 / 14:39:20 / cg"
       
  4474     "Modified: / 30-06-2016 / 17:43:46 / cg"
       
  4475 ! !
  4472 ! !
  4476 
  4473 
  4477 !Win32OperatingSystem class methodsFor:'file access'!
  4474 !Win32OperatingSystem class methodsFor:'file access'!
  4478 
  4475 
  4479 closeFd:anIntegerOrHandle
  4476 closeFd:anIntegerOrHandle