skpm / child_process Goto Github PK
View Code? Open in Web Editor NEWDrop-in replacement for the child_process NodeJS package
License: MIT License
Drop-in replacement for the child_process NodeJS package
License: MIT License
The pid
property is always 0 in my testing.
var subprocess = spawn('mycmd')
subprocess.pid // => 0
It looks like calling processIdentifier()
before launch()
will give you a 0
:
var task = NSTask.alloc().init()
task.processIdentifier() // => 0
result.pid
is being set to String(task.processIdentifier())
but this happens before launch()
is called because that is done via setImmediate()
here:
Line 216 in 0513aed
import { exec } from '@skpm/child_process';
export default function test() {
exec('echo test', (err, stdout, stderr) => {
console.log('err', err);
console.log('stdout', stdout);
console.log('stderr', stderr);
});
}
Error: Unknown encoding: NSData
Line 141 in 0513aed
The readme says all child_process
methods are supported, but I don't see fork
I noticed this while playing around, and I can't quite figure out the cause. When running certain commands asynchronously, the module fails to release the fiber it opens, which causes a large memory leak. Further, the commands never return any values. For example:
exec('/bin/ps', null, (error, stdout, stderr) => {
log(`DEBUG: ${stdout}`);
log(`DEBUG: ${stderr}`);
});
Will hang and cause Sketch to eat memory, as well as fill up the Console really quickly:
The output I would expect is:
❯ ps
PID TTY TIME CMD
16534 ttys001 0:02.87 /usr/local/bin/zsh -l
10772 ttys003 0:02.60 /usr/local/bin/zsh -l
30746 ttys003 0:00.29 node /usr/local/Cellar/yarn/1.13.0/libexec/bin/yarn.js watch
30088 ttys005 0:00.74 /usr/local/bin/zsh --login
Hi,
i need to run code in nodejs. So my idea was to spawn a nodejs process and communicate with it by sending jsonl messages to stdin (you call it sdtin) & getting jsonl messages back from stdout.
But when i attempt to write to stdin it just crashes sketch. No crash reports in console.
const child = spawn(
path.resolve(process.cwd(), "./Contents/Sketch/external"),
[],
{cwd: path.resolve(process.cwd(), "./Contents/Sketch")},
);
// @ts-ignore
const stdin: Writable = child.stdin || child.sdtin;
const buf = Buffer.from(JSON.stringify({type: "getImages"}) + "\n");
console.log("buf", buf);
await new Promise<void>((onOk, onErr) => {
// crashes here
stdin.write(buf, (err) => {
if (err !== null && err !== undefined) {
onErr(err);
} else {
onOk();
}
});
});
I called exec in my Sketch Plugin, but the return value cannot be returned completely, it can only return 4060 characters. Can you help me?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.