I am trying to call a python script using node.js child process.
JS
console.log('Hello World!')
const path = require('path')
const {spawn} = require('child_process')
/**
* Run python script, pass in `-u` to not buffer console output
* #return {ChildProcess}
*/
function runScript(){
return spawn('python', [
"-u",
path.join(__dirname, 'pythonscript.py'),
"--foo", "some value for foo",
]);
}
const subprocess = runScript()
// print output of script
subprocess.stdout.on('data', (data) => {
console.log(`data:${data}`);
});
subprocess.stderr.on('data', (data) => {
console.log(`error:${data}`);
});
subprocess.stderr.on('close', () => {
console.log("Closed");
});
python
mydict = {
"brand": "Ford",
"model": "Mustang",
"licensePlate" : "O XXX YYY",
"year" : 1964,
"insured": {
'lastname' : 'Snow',
'firstname' : 'John',
'adress' : 'Holiday street, 4 - Paradise'
}
}
print(mydict)
The purpose is to be able to use the dictionary created by the python code in javascript.
But a this step I am faced to an error which is provided here below.
Hello World!
events.js:291
throw er; // Unhandled 'error' event
^
Error: spawn python ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:268:19)
at onErrorNT (internal/child_process.js:470:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
Emitted 'error' event on ChildProcess instance at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:274:12)
at onErrorNT (internal/child_process.js:470:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
errno: 'ENOENT',
code: 'ENOENT',
syscall: 'spawn python',
path: 'python',
spawnargs: [
'-u',
'/mnt/c/Users/xxxx/javascript/pythonscript.py',
'--foo',
'some value for foo'
]
}
can you help me with this? I work with Ubuntu Bash for Windows 10, I don't know if this information is relevant or not...
Related
I was trying to run a github program from https://github.com/StartBootstrap/sb-clean-blog-angular .
I faced this error when I run the command "npm start".
D:\Full-Stack-Development-Capstone\Frontend\sb-clean-blog-angular-1.2.0\scripts\start.js:14
}).then(success, failure);
^
TypeError: concurrently(...).then is not a function
at Object.<anonymous> (D:\Full-Stack-Development-Capstone\Frontend\sb-clean-blog-angular-1.2.0\scripts\start.js:14:4)
at Module._compile (node:internal/modules/cjs/loader:1112:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1166:10)
at Module.load (node:internal/modules/cjs/loader:988:32)
at Module._load (node:internal/modules/cjs/loader:834:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47
Node.js v18.4.0
The script code
const concurrently = require('concurrently');
const port = process.env.PORT || 4200;
concurrently([
{ command: 'node scripts/pug-watch.js', name: 'PUG_WATCH', prefixColor: 'bgGreen.bold' },
{
command: `npm run ng -- serve --port ${port} --open`,
name: 'NG_SERVE',
prefixColor: 'bgBlue.bold',
}
], {
prefix: 'name',
killOthers: ['failure', 'success'],
}).then(success, failure);
function success() {
console.log('Success');
}
function failure() {
console.log('Failure');
}
Hi to fix this simply do this
const { result } = concurrently([
{ command: 'node scripts/pug-watch.js', name: 'PUG_WATCH', prefixColor: 'bgGreen.bold' },
{
command: `npm run ng -- serve --port ${port} --open`,
name: 'NG_SERVE',
prefixColor: 'bgBlue.bold',
}
], {
prefix: 'name',
killOthers: ['failure', 'success'],
});
result.then(success, failure);
can read more on it here.
https://github.com/open-cli-tools/concurrently#api
I'm trying to compress the picture before $npm run build:test in my project(Vue3 + vite)
I wrote a script
I need to overwrite the original image. There are multiple folders under assets / images, so you need to solve the path problem of dist and use imagemin Buffer to rewrite
"prebuild:test": "node imagemin.mjs",
"build:test": "vue-tsc --noEmit && vite build --mode test",
When I execute Npm run build:test
I found him not compressed
Here's my code and my error log
async function processFile(filePath) {
// filePath = 'src/**/*.{jpg,png,svg,gif}'
let buffer = await fs.readFile(filePath);
let content;
try {
content = await imagemin.buffer(buffer, {
plugins
});
const size = content.byteLength,
oldSize = buffer.byteLength;
if (tinyMap.get(filePath)) {
tinyMap.set(filePath, {
...tinyMap.get(filePath),
size: size / 1024,
oldSize: oldSize / 1024,
ratio: size / oldSize - 1
});
} else {
tinyMap.set(filePath, {
size: size / 1024,
oldSize: oldSize / 1024,
ratio: size / oldSize - 1
});
}
return content;
} catch (error) {
console.log(error)
console.error('imagemin error:' + filePath);
}
}
Error Msg
Error: spawn /Users/XXXXX/node_modules/optipng-bin/vendor/optipng ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19)
at onErrorNT (internal/child_process.js:467:16)
at processTicksAndRejections (internal/process/task_queues.js:82:21) {
errno: -2,
code: 'ENOENT',
syscall: 'spawn /Users/XXXXX/node_modules/optipng-bin/vendor/optipng',
path: '/Users/XXXX/node_modules/optipng-bin/vendor/optipng',
spawnargs: [
'-strip',
'all',
'-clobber',
'-o',
7,
'-out',
'/private/var/folders/kf/nr04_xcd22q5v98q2mfftdmc0000gn/T/b8a43d55-094f-4cab-971d-8d2372562498',
'-fix',
'-i',
'0',
'/private/var/folders/kf/nr04_xcd22q5v98q2mfftdmc0000gn/T/fb9379a3-32f2-4499-b460-2c5bf6a95763'
],
killed: false,
stdout: '',
stderr: '',
failed: true,
signal: null,
cmd: '/Users/tuzhixiang/XXXXX/node_modules/optipng-bin/vendor/optipng -strip all -clobber -o 7 -out /private/var/folders/kf/nr04_xcd22q5v98q2mfftdmc0000gn/T/b8a43d55-094f-4cab-971d-8d2372562498 -fix -i 0 /private/var/folders/kf/nr04_xcd22q5v98q2mfftdmc0000gn/T/fb9379a3-32f2-4499-b460-2c5bf6a95763',
timedOut: false
}
imagemin error:src/view/radar/img/radar-bg.png
I installed goQuorum with quorum-wizard with 4 quorum nodes and 4 tessera nodes on IBFT. When I start the network with "./start.sh" I get
Starting Quorum network...
Waiting until all Tessera nodes are running...
Waiting until all Tessera nodes are running...
All Tessera nodes started
Starting Quorum nodes
Successfully started Quorum network.
--------------------------------------------------------------------------------
Tessera Node 1 public key:
BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo=
Tessera Node 2 public key:
QfeDAys9MPDs2XHExtc84jKGHxZg/aj52DTh0vtA3Xc=
Tessera Node 3 public key:
1iTZde/ndBHvzhcl7V68x44Vx7pl8nwx9LqnM/AfJUg=
Tessera Node 4 public key:
oNspPPgszVUFw0qmGFfWwh1uxVUXgvBxleXORHj07g8=
--------------------------------------------------------------------------------
when I run "nmap -p 21000-21100" I get
21000/tcp open irtrans
21001/tcp open unknown
21002/tcp open unknown
21003/tcp open unknown
This is my truffle-config.js
const HDWalletProvider = require("#truffle/hdwallet-provider");
const mnemonic = "not my real mn mon ic num phrase dum get l gg";
module.exports = {
networks: {
rinkeby: {
provider: function() {
return new HDWalletProvider(mnemonic, "https://rinkeby.infura.io/v3/"+mnemonic);
},
network_id: '*',
timeoutBlocks: 100000,
networkCheckTimeout:2000000
},
quorum: {
provider: function() {
return new HDWalletProvider(mnemonic, "http://127.0.0.1:21000/", chainId=10);
},
network_id: '*',
type: 'quorum',
timeoutBlocks: 100000,
networkCheckTimeout:2000000
},
compilers: {
solc: {
version: "0.5.0",
settings: {
optimizer: {
enabled: true, // Default: false
runs: 1000 // Default: 200
},
evmVersion: "homestead" // Default: "byzantium"
}
}
}
};
When I cd in to the directory with the truffle-config.js and I run truffle deploy --reset --network quorum to compile my smart contracts I get the following error.
Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.
/root/dapp1/Dapp/node_modules/web3-core-helpers/src/errors.js:42
return new Error(message);
^
Error: PollingBlockTracker - encountered an error while attempting to update latest block:
Error: Invalid JSON RPC response: ""
at Object.InvalidResponse (/root/dapp1/Dapp/node_modules/web3-core-helpers/src/errors.js:42:16)
at XMLHttpRequest.request.onreadystatechange (/root/dapp1/Dapp/node_modules/web3-providers-http/src/index.js:92:32)
at XMLHttpRequestEventTarget.dispatchEvent (/root/dapp1/Dapp/node_modules/xhr2-cookies/xml-http-request-event-target.ts:44:13)
at XMLHttpRequest._setReadyState (/root/dapp1/Dapp/node_modules/xhr2-cookies/xml-http-request.ts:219:8)
at XMLHttpRequest._onHttpRequestError (/root/dapp1/Dapp/node_modules/xhr2-cookies/xml-http-request.ts:379:8)
at ClientRequest.<anonymous> (/root/dapp1/Dapp/node_modules/xhr2-cookies/xml-http-request.ts:266:37)
at ClientRequest.emit (events.js:315:20)
at Socket.socketOnEnd (_http_client.js:493:9)
at Socket.emit (events.js:327:22)
at endReadableNT (internal/streams/readable.js:1327:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
at PollingBlockTracker._performSync (/root/dapp1/Dapp/node_modules/eth-block-tracker/src/polling.js:51:24)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
I can deploy the smart contracts to rinkeby test net within this environment but I can't get smart contracts to deploy to quorum
I am using
Node v14.16.1
Ubuntu 18.04 (64 Bit)
Quorum 21.1.0
Web3.js v1.3.5
Truffle v5.3.4 (core: 5.3.4)
solidity v0.5.0
I've not used truffle with HDWalletProvider, which I believe is from an older version of Truffle. I'm not certain that will set up the node connection.
We would normally set up the configuration like the following in the quorum: {} section:
host: "localhost",
port: 22001,
type: "quorum"
I would suggest using that and see if it works.
Take a look at the truffle docs for working with quorum: https://www.trufflesuite.com/docs/truffle/distributed-ledger-support/working-with-quorum
Did you change from the default ports in the quorum-wizard?
The default for the node 1 RPC is 22000, the 21000 range is for p2p networking.
I would set the host and port per Satpal's answer above, as in the hdwallet documentation here.
I'm heaving problems with permission on running this CUPS command : cancel -a where -a is the option to cancel all jobs on all printers.
this is all the output in console:
error: Error: spawnSync /home/finsoft EACCES
at Object.spawnSync (internal/child_process.js:1041:20)
at spawnSync (child_process.js:616:24)
at Object.cancelAll (/home/finsoft/ProgettoStampantiLinux/ProgettoStampanti/api/cupsApis.js:155:19)
at /home/finsoft/ProgettoStampantiLinux/ProgettoStampanti/app.js:80:24
at Layer.handle [as handle_request] (/home/finsoft/ProgettoStampantiLinux/ProgettoStampanti/node_modules/express/lib/router/layer.js:95:5)
at next (/home/finsoft/ProgettoStampantiLinux/ProgettoStampanti/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/home/finsoft/ProgettoStampantiLinux/ProgettoStampanti/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/home/finsoft/ProgettoStampantiLinux/ProgettoStampanti/node_modules/express/lib/router/layer.js:95:5)
at /home/finsoft/ProgettoStampantiLinux/ProgettoStampanti/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/home/finsoft/ProgettoStampantiLinux/ProgettoStampanti/node_modules/express/lib/router/index.js:335:12) {
errno: 'EACCES',
code: 'EACCES',
syscall: 'spawnSync /home/finsoft',
path: '/home/finsoft',
spawnargs: [ '-c', 'cancel -u' ]
},
status: null,
signal: null,
output: null,
pid: 9826,
stdout: null,
stderr: null
}
this is my spawnSync function:
cancelAll = function () {
let args = ["-a"];
let cancelAll = spawnSync("cancel", args, { encoding: "utf-8", shell: '/home/finsoft'});
// console.log(cancelAll);
return cancelAll;
};
the option shell:'/home/finsoft' is the path to the shell I want to use.
what I did until now:
1)I tried adding to the root group the user used in the spawnSync, which is finsoft, and i double checked it by running this:
let args = ["-u"];
args.push('finsoft');
let uid = spawnSync('id', args, { encoding: "utf-8"});
console.log(uid);
output of the console.log(uid):
{
status: 0,
signal: null,
output: [ null, '1000\n', '' ],
pid: 8141,
stdout: '1000\n',
stderr: ''
}
the witch correspond to the finsoft uid
2)i changed the permissions of /home/finsoft like this:
sudo chmod 777 /home/finsoft
the result of ls-l:
finsoft#finsoft-20351:/home$ ls -l
total 4
drwxrwxrwx 34 finsoft finsoft 4096 Feb 23 09:11 finsoft
I even tried to specify the option uid:0 in the spawnSync, it should use the root user, and changed the shell path to its default(/bin/sh), so i shouldn't have problems with permissions or other requirements stuff, but that gives a totally different error:
Error: spawnSync /bin/sh EPERM
What else can I try?
var gm = require("gm").subClass({ imageMagick: true });
function conversion(image) {
const image = gm(image);
image.orientation(function(err, value) {
if (err) {
console.log("Error Occurred :",err);
}
}
While accessing image.orientation this is the error which occurs.
Error: write EPIPE
at afterWriteDispatched (internal/stream_base_commons.js:154:25)
at writeGeneric (internal/stream_base_commons.js:145:3)
at Socket._writeGeneric (net.js:786:11)
at Socket._write (net.js:798:8)
at doWrite (_stream_writable.js:403:12)
at writeOrBuffer (_stream_writable.js:387:5)
at Socket.Writable.write (_stream_writable.js:318:11)
at gm._spawn (/var/task/node_modules/gm/lib/command.js:253:18)
at gm._exec (/var/task/node_modules/gm/lib/command.js:190:17)
at gm.proto.<computed> [as orientation] (/var/task/node_modules/gm/lib/getters.js:68:12) {
errno: 'EPIPE',
code: 'EPIPE',
syscall: 'write'
}
These are some steps which i have already performed.
i have tried installing both imagemagick and graphicsmagick. https://www.npmjs.com/package/gm
Also there was suggestion to reinstall imagemagick and graphicsmagick and testing after restarting system. it also didn't worked
i am using Ubuntu , npm gm version:"^1.23.1", node version : nodejs12.x