child_process#SpawnSyncReturns TypeScript Examples
The following examples show how to use
child_process#SpawnSyncReturns.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: spawn.ts From gitmars with GNU General Public License v3.0 | 6 votes |
/**
* 异步执行脚本
*
* @param client - 执行脚本的宿主,名称
* @param argv - 参数
* @param options - 透传配置
* @returns result - 返回执行状态
*/
export function spawn(
client: string,
argv: string[],
options: SpawnOptions = {}
): Partial<SpawnSyncReturns<string>> {
let len = argv.length
while (len--) {
!argv[len] && argv.splice(len, 1)
}
const program = crossSpawn.sync(client, argv, {
// stdio: 'inherit',
shell: process.platform === 'win32',
...options
})
debug(client, argv)
return {
pid: program.pid,
stdout: program.stdout
? program.stdout.toString().replace(/\s+$/, '')
: '',
stderr: program.stderr ? program.stderr.toString() : '',
status: program.status,
signal: program.signal,
error: program.error
}
}
Example #2
Source File: spawn.ts From gitmars with GNU General Public License v3.0 | 6 votes |
/**
* 同步执行脚本
*
* @param client - 执行脚本的宿主,名称
* @param argv - 参数
* @param options - 透传配置
* @returns result - 返回执行状态
*/
export function spawnSync(
client: string,
argv: string[],
options: SpawnSyncOptions = {}
): Partial<SpawnSyncReturns<string>> {
let len = argv.length
while (len--) {
!argv[len] && argv.splice(len, 1)
}
const program = crossSpawn.sync(client, argv, {
// stdio: 'inherit',
shell: process.platform === 'win32',
...options
})
debug(client, argv)
return {
pid: program.pid,
stdout: program.stdout
? program.stdout.toString().replace(/\s+$/, '')
: '',
stderr: program.stderr ? program.stderr.toString() : '',
status: program.status,
signal: program.signal,
error: program.error
}
}
Example #3
Source File: pycompile-op.ts From algo-builder with Apache License 2.0 | 6 votes |
/**
* Description: Runs a subprocess to execute python script
* @param filename : python filename in assets folder
* @param scInitParam : Smart contract initialization parameters.
*/
private runPythonScript(filename: string, scInitParam?: string): SpawnSyncReturns<string> {
const filePath = getPathFromDirRecursive(ASSETS_DIR, filename) as string;
// used spawnSync instead of spawn, as it is synchronous
if (scInitParam === undefined) {
return spawnSync("python3", [filePath], { encoding: "utf8" });
}
return spawnSync("python3", [filePath, scInitParam], { encoding: "utf8" });
}
Example #4
Source File: pycompile-op.ts From algo-builder with Apache License 2.0 | 6 votes |
/**
* Description: returns TEAL code using pyTeal compiler
* @param filename : python filename in assets folder
* @param scInitParam : Smart contract initialization parameters.
*/
compilePyTeal(filename: string, scInitParam?: string): string {
const subprocess: SpawnSyncReturns<string> = this.runPythonScript(filename, scInitParam);
if (subprocess.stderr) {
throw new BuilderError(ERRORS.PyTEAL.PYTEAL_FILE_ERROR, {
filename: filename,
reason: subprocess.stderr,
});
}
return subprocess.stdout;
}
Example #5
Source File: common.ts From solc-typed-ast with Apache License 2.0 | 5 votes |
export function SolAstCompileExec(...params: string[]): SpawnSyncReturns<string> {
return spawnSync("sol-ast-compile", params, { encoding: "utf8" });
}