Idris2/support/js/support_system.js
Mathew Polzin 4220c644cf
Add a few missing NodeJS FFI functions to System (#2271)
* support for system command via node backend.

* Add env var set/unset

* fix env unset function

* Update libs/base/System.idr

* modify system test to cover node and chez.

* Add base tests for env get/set
2022-01-18 22:43:03 -08:00

23 lines
567 B
JavaScript

const support_system_child_process = require('child_process')
function support_system_spawnSync(cmd) {
const options = { shell: true, stdio: 'inherit' }
const { status } = support_system_child_process.spawnSync(cmd, [], options)
return status
}
// call with overwrite == 0 to avoid overwriting an existing variable.
function support_system_setEnv(name, value, overwrite) {
if (overwrite == 0 && process.env[name]) {
return 0
}
process.env[name] = value
return 0
}
function support_system_unsetEnv(name) {
delete process.env[name]
return 0
}