31 lines
966 B
JavaScript
31 lines
966 B
JavaScript
|
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
|