在nodejs脚本中,我有以下代码同步调用并从我调用的shell脚本返回stdout:
var sh = require('shelljs');
... some code
var output = sh.exec('./someshellscript.sh', {silent:true}).stdout;
console.log(output);
... some more code (that shouldnt run until the script is complete)
Run Code Online (Sandbox Code Playgroud)
我还可以运行以下脚本,它将返回stderr:
var sh = require('shelljs');
... some code
var output = sh.exec('./someshellscript.sh', {silent:true}).stderr;
console.log(output);
... some more code (that shouldnt run until the script is complete)
Run Code Online (Sandbox Code Playgroud)
但是我希望在同步调用中同时接收stdout和stderr.它可能是我在这里失踪的非常明显但我无法解决的问题.
我认为你曾经能够在以前的版本中运行以下命令,但这只是现在返回undefined:
var sh = require('shelljs');
... some code
var output = sh.exec('./someshellscript.sh', {silent:true}).output;
console.log(output);
... some more code (that shouldnt run until the script is complete)
Run Code Online (Sandbox Code Playgroud)
相关软件版本为: …
当我在节点中运行以下代码时:
var shell = require('shelljs');
var files = shell.ls('-R', './**/foobar');
console.log('Files found:\n' + files.join('\n'));
Run Code Online (Sandbox Code Playgroud)
我在输出中看到了这一点:
ls: no such file or directory: ./**/foobar
Run Code Online (Sandbox Code Playgroud)
如何抑制stderr,使其不被显示?
我想使用shelljs在javascript中编写一些脚本,因为我想使用一些新的JavaScript功能,所以我使用Babel + webpack将我的代码捆绑到一个bundle js中。
代码很简单:
entry.js
import shell from 'shelljs'
shell.exec('ls')
Run Code Online (Sandbox Code Playgroud)
webpack.conf.js
module.exports = {
mode: "development",
target: 'node',
entry: './entry.js',
output: {
path: __dirname,
filename: './dist/bundle.js'
},
module: {
rules: [{
test: /\.js$/,
use: [{
loader: 'babel-loader', options: {
presets: ['@babel/preset-env']
}
}]
}]
}
}
Run Code Online (Sandbox Code Playgroud)
package.json
{
"scripts": {
"demo": "webpack && node ./dist/bundle.js"
},
"devDependencies": {
"@babel/core": "7.2.2",
"@babel/preset-env": "7.4.2",
"babel-loader": "8.0.6",
"webpack": "4.28.1",
"webpack-cli": "3.2.1"
},
"dependencies": {
"shelljs": "0.8.3"
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行“ npm install && …
我想在shelljs节点来设置环境变量
所以这里的psudo代码:
const shell = require('shelljs');
shell.exec('export MM=2');
shell.exec('echo $MM');
Run Code Online (Sandbox Code Playgroud)
但这并不能打印输出的值 MM
关于如何设置通过节点与环境变量的任何建议export(执行bash命令)?
我试图在我的核心React组件中要求shelljs.
import React, { Component } from 'react';
import {render} from 'react-dom';
import Header from './components/Header';
const shell = require('shelljs');
class App extends Component {
render() {
console.log("First component mounting");
console.log("First component mounting");
return (
<Header />
)
}
}
render(<App />, document.getElementById('root'));
Run Code Online (Sandbox Code Playgroud)
我跑的时候
webpack build
Run Code Online (Sandbox Code Playgroud)
我没有错误,然后我运行我的服务器,我得到以下控制台错误.
我使用jekyll作为我的服务器端.目前正在从正常的jekyll实现过渡到React.React很好实现,因为我在导入shelljs模块之前测试了Header组件
ReferenceError: process is not defined
Run Code Online (Sandbox Code Playgroud)
我是新手在javascript中使用模块,提前谢谢.
我需要访问 Bull-queue 以查看工作统计信息并显示在页面上。我正在使用bull-repl从 CLI 访问队列,如下所示:
> bull-repl
BULL-REPL> connect marathon reddis://localhost:6379
Connected to reddis://localhost:6379, queue: marathon
BULL-REPL | marathon> stats
??????????????????????
? (index) ? Values ?
??????????????????????
? waiting ? 0 ?
? active ? 0 ?
? completed ? 55 ?
? failed ? 1 ?
? delayed ? 0 ?
? paused ? 0 ?
??????????????????????
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用以下代码从 JS 中执行相同的操作:
const shell = require('shelljs');
const ccommandExistsSync = require('command-exists').sync;
function installBullRepl(){
if(ccommandExistsSync('bull-repl')){
queueStats();
} else{
shell.exec('npm i -g …Run Code Online (Sandbox Code Playgroud) shelljs ×6
node.js ×4
javascript ×2
ecmascript-6 ×1
npm ×1
reactjs ×1
task-queue ×1
webpack ×1