Last active
September 21, 2017 15:35
-
-
Save atrauzzi/bbcc171b57a7ea276a2e6bf6419c7e51 to your computer and use it in GitHub Desktop.
A utility to spawn commands using C# from edgejs in nodejs & TypeScript!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@atrauzzi can you post the code you would use with "native"
child_process
?