Skip to content

Commit

Permalink
Add GtOsSystemInfo>>findExecutable:
Browse files Browse the repository at this point in the history
  • Loading branch information
akgrant43 committed Oct 21, 2024
1 parent 461b6f8 commit 9211e3f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/GToolkit-Utility-System/GtOsSystemInfo.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@ GtOsSystemInfo >> currentProcessId [
^ self subclassResponsibility
]

{ #category : #accessing }
GtOsSystemInfo >> findExecutable: aString [
"Do a which/where on the supplied executable name
Run this is a shell to ensure that all logon configuration is performed."
| builder output path |

builder := GtExternalProcessBuilder new
command: (Smalltalk os environment at: 'SHELL');
args: {
'-l'.
'-c'.
'which ', aString asString }.
output := builder output.
output status isSuccess
ifFalse: [ ^ self error: 'Unable to find: ', aString asString, ', process failed to run' ].
path := output stdout trimBoth.
path ifEmpty: [ self error: 'Unable to find: ', aString asString, ', executable not found' ].
^ path asFileReference
]

{ #category : #'cpu info' }
GtOsSystemInfo >> freeMemory [
"Answer the free RAM of the host in bytes"
Expand Down
21 changes: 21 additions & 0 deletions src/GToolkit-Utility-System/GtWindowsSystemInfo.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,27 @@ GtWindowsSystemInfo >> currentProcessId [
^ self ffiCall: #(#uint #GetCurrentProcessId #()) module: 'Kernel32.dll'
]

{ #category : #accessing }
GtWindowsSystemInfo >> findExecutable: aString [
"Do a which/where on the supplied executable name
Run this is a shell to ensure that all logon configuration is performed."
| builder output path lines |

builder := GtExternalProcessBuilder new
command: 'where';
args: { aString }.
output := builder output.
output status isSuccess
ifFalse: [ ^ self error: 'Unable to find: ', aString asString, ', process failed to run' ].
path := output stdout trimBoth.
path ifEmpty: [ self error: 'Unable to find: ', aString asString, ', executable not found' ].
lines := path lines
collect: [ :line | line trimBoth asFileReference ]
thenSelect: [ :each | #(bat exe) includes: each extension asLowercase ].
lines ifEmpty: [ self error: 'Unable to find: ', aString asString, ', executable not found' ].
^ lines first.
]

{ #category : #'cpu info' }
GtWindowsSystemInfo >> freeMemory [
"Answer the free RAM of the host"
Expand Down

0 comments on commit 9211e3f

Please sign in to comment.