Skip to content

Instantly share code, notes, and snippets.

@atrauzzi
Last active September 21, 2017 15:35
Show Gist options
  • Save atrauzzi/bbcc171b57a7ea276a2e6bf6419c7e51 to your computer and use it in GitHub Desktop.
Save atrauzzi/bbcc171b57a7ea276a2e6bf6419c7e51 to your computer and use it in GitHub Desktop.
A utility to spawn commands using C# from edgejs in nodejs & TypeScript!
// tslint:disable-next-line:no-var-requires
const edge = require("edge-js");
export interface Options {
fileName: string;
arguments?: string;
}
export async function spawn(options: Options) {
options = {
arguments: "",
...options,
};
const deferred = {} as any;
deferred.promise = new Promise<null>((resolve, reject) => {
deferred.resolve = resolve;
deferred.reject = reject;
});
const edgeFunction = edge.func(`
async (dynamic input) => {
var process = new System.Diagnostics.Process();
process.StartInfo = new System.Diagnostics.ProcessStartInfo {
WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden,
FileName = input.fileName,
Arguments = input.arguments,
};
process.Start();
return null;
}
`);
edgeFunction(options, (error: any, result: null) => {
if (error) {
deferred.reject(error);
}
else {
deferred.resolve(result);
}
});
await deferred.promise;
}
@refack
Copy link

refack commented Sep 21, 2017

@atrauzzi can you post the code you would use with "native" child_process?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment