Argument vector to execute
Optional
opts: SpawnOptions & { @45drives/cockpit-typings!spawn cockpit.spawn() options
Optional
stderr: "message" | "out"where to pipe stderr of proc
the process state object
import { useSpawn, errorString } from '@45drives/cockpit-helpers';
async function getHostnameAsync() {
try {
const state = useSpawn(['hostname'], { superuser: 'try' });
const hostname = (await state.promise()).stdout;
return hostname;
} catch (state) {
console.error(errorString(state));
return null;
}
}
function getHostnamePromise() {
return new Promise((resolve, reject) => {
const state = useSpawn(['hostname'], { superuser: 'try' });
state.promise()
.then(({stdout}) => resolve(stdout))
.catch(state => {
console.error(errorString(state))
reject(null);
});
});
}
Optional
opts: SpawnOptions & { Optional
stderr: "message" | "out"
Wrapper for using @45drives/cockpit-typings!spawn cockpit.spawn()
Executes process in argv on the server (or on opts.host if defined), and returns output in SpawnState.stdout