
Security News
NVD Quietly Sweeps 100K+ CVEs Into a “Deferred” Black Hole
NVD now marks all pre-2018 CVEs as "Deferred," signaling it will no longer enrich older vulnerabilities, further eroding trust in its data.
compile-run
Advanced tools
async/await
and promises
.The following should be installed on your machine and be added to the path.
Language | Software |
---|---|
C | gcc |
C++ | gcc |
Java | jdk |
Python | python |
JavaScript(in node.js environment) | node.js |
The library stores the source files for programs in the home directory in a folder named .compile-run2
. Make sure you have permissions for this folder.
You can install it by using npm
like below.
npm install compile-run --save
It have 5 modules each for a language containing namely.
const {c, cpp, node, python, java} = require('compile-run');
Each module have 2 functions :-
runFile
This enables you to run a file and takes filepath as an argument with options and callback as optional arguments.
runSource
This enables you to directly execute a source code in a stored in a string. It takes source code as an argument with options and callback as optional arguments.
let resultPromise = cpp.runFile('E:\\abcd.cpp', { stdin:'3\n2 '});
resultPromise
.then(result => {
console.log(result);//result object
})
.catch(err => {
console.log(err);
});
const sourcecode = `print("Hell0 W0rld!")`;
let resultPromise = python.runSource(sourcecode);
resultPromise
.then(result => {
console.log(result);
})
.catch(err => {
console.log(err);
});
You can also use callback by passing it like -
cpp.runFile('E:\\abcd.cpp', { stdin:'3\n2 '}, (err, result) => {
if(err){
console.log(err);
}
else{
console.log(result);
}
});
cpp.runFile('E:\\abcd.cpp', (err, result) => {
if(err){
console.log(err);
}
else{
console.log(result);
}
});
// Providing custom path in java
java.runFile('E:\\Main.java',{
compilationPath: '<path to javac>',
executionPath: '<path to java>'
},(err,result)=>console.log(err ? err : result));
//I have 2 versions of python installed 2.7 and 3.6. I can use 3.6 using python3
//to run python3 using compile-run I can do something like
python.runFile('/home/projects/scripts/abc.py',{
executionPath: 'python3'
},(err,result)=>console.log(err ? err : result));
//If I want to provide custom path of gcc in cpp
cpp.runFile('E:\\abc.cpp',{
compilationPath: '<path to gcc>' // something like C:\\Program Files\\gcc\\bin
},(err,result)=>console.log(err ? err : result));
Result is an object with the following keys:-
stdout
<string> - stdout of the program execution. For empty stdout an empty string is returned.stderr
<string> - stderr of the program execution, compilation or if public class name is not found in provided source string(In java). For empty stderr empty string is returned.exitCode
<number> - exit code of the program.errorType
<string|undefined> - It is set to the below values if there is some stderr or in case of a non-zero exitCode.
'pre-compile-time'
- Only in case of java
. Can be arised due to invalid public class name if using runSource
for java
.'compile-time'
- If some error has occured at the compile time.'run-time'
- If the error has occured at the run time.cpuUsage
<number> - CPU Time as calculated in microseconds.memoryUsage
<number> - Memory Consumed in Bytes.signal
<string|null> - Signal resulting, if any, resulting from the code execution.cpuUsage
and memoryUsage
.API's offer an optional options object which has following keys:-
stdin
<string> - Input/stdin you want to pass to the program.timeout
<number> - timeout for program execution in milliseconds. Default is 3000 milliseconds.compileTimeout
- timeout during compilation for c, cpp, java in milliseconds. Default is 3000 milliseconds. Would be ignored if passed for node or pythoncompilationPath
- path for the compiler for c, cpp and java i.e for gcc and javac respectively. These paths defined by you if provided else defaults would be used.executionPath
- path for the command to execute the program used in java, python, nodejs i.e for java
, python
and node
respectively. These paths defined by you if provided else defaults would be used.The versions < 2.x.x have been deprecated due to inconsistencies so its recommended to use version > 2.0.0.
You can find compile run version 1.x.x at https://github.com/vibhor1997a/compile-run-1.
FAQs
You can execute programs in different languages using this package
We found that compile-run demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NVD now marks all pre-2018 CVEs as "Deferred," signaling it will no longer enrich older vulnerabilities, further eroding trust in its data.
Research
Security News
Lazarus-linked threat actors expand their npm malware campaign with new RAT loaders, hex obfuscation, and over 5,600 downloads across 11 packages.
Security News
Safari 18.4 adds support for Iterator Helpers and two other TC39 JavaScript features, bringing full cross-browser coverage to key parts of the ECMAScript spec.