You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
maestro/app/classes/metal/LocalHost.js

31 lines
966 B

const Host = require('./Host')
const child_process = require('child_process')
const ExecutionResult = require('../logical/ExecutionResult')
const fs = require('fs')
class LocalHost extends Host {
async execute(command) {
const result = new ExecutionResult()
return new Promise((resolve) => {
child_process.exec(command, (error, stdout, stderr) => {
result.exit(error ? error.code : 0)
result.out(stdout)
result.error(stderr)
resolve(result)
})
})
}
async open_file_read_stream(file_path) {
file_path = typeof file_path === 'string' ? file_path : file_path.path
return fs.createReadStream(file_path)
}
async open_file_write_stream(file_path) {
file_path = typeof file_path === 'string' ? file_path : file_path.path
return fs.createWriteStream(file_path)
}
}
module.exports = exports = LocalHost