-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
shell.exec bug #3
Comments
shell.exec run export not work #!/usr/bin/env node
const shell = require("shelljs");
const key = 'PORT_ENV';
const env = 8888;
// const command = `export ${key}=${env}`;
// const command = `set ${key}=${env}`;
const command = 'export PORT_ENV=8888';
// shelljs 执行 command
shell.exec('whoami');
shell.exec('which sh');
shell.exec('which bash');
// shell.exec('pwd');
// shell.exec('ls -al');
shell.exec(command);
console.log('\n command =', command);
console.log('\n PORT_ENV =', process.env.PORT_ENV);
|
$ spe PORT_ENV=666 && node ./test.js
# ❌
$ spe PORT_ENV=666 && node -e "console.log('PORT_ENV =', process.env.PORT_ENV);"
$ node ./spe-bug.js
# ✅
$ export PORT_ENV=8090 && node -e "console.log('PORT_ENV =', process.env.PORT_ENV);"
|
process bug ???
If you are the child process (the process that got execed), you can not set the environment variable of your parent process. https://stackoverflow.com/questions/49372501/set-environment-variable-with-shelljs 在所有 UNIX 和 类Unix系统中, 每个进程都有其各自的环境变量设置。 缺省情况下, 当一个进程被创建时, 除了创建过程中的明确更改外,它继承了其父进程的绝大部分环境设置。 https://en.wikipedia.org/wiki/Environment_variable // shell.exec(command);
if(isMac) {
// command = `export ${key}=${env}`;
// shell.exec(command);
// shell.env[`"${key}"`] = env;
} else {
// command = `set ${key}=${env}`;
// shell.exec(command);
// shell.env[`"${key}"`] = env;
}
// shell.env['"' + key + '"'] = env;
// shell.env[`"${key}"`] = env;
shell.env[key] = env;
console.log('\n🎉 finished!');
不同的 node.js child process env /* spe PORT_ENV=8090 && node ./bug.js spe PORT_ENV=8090 && node -e "console.log('PORT_ENV =', process.env.PORT_ENV);" */ |
Linux 权限管理https://www.imooc.com/search/?type=course&words=Linux https://www.imooc.com/learn/481 shell 正则表达式https://www.imooc.com/learn/378 shell 编程之条件判断与流程控制https://www.imooc.com/learn/408 《Tony老师聊shell》 |
shell编程之环境变量配置文件 ✅https://www.imooc.com/learn/361 shell编程之变量 ✅ |
兄弟连-沈超 云计算教学总监,国内著名的 Linux 技术专家,十余年 Linux 从业经验,培训学员过万名,录制的 Linux 教学视频过百万次下载,曾获微软认证、红帽认证讲师、北京市优秀园丁奖…历任即时科研集团项目经理、光宇华夏游戏运维部高级工程师,负责百万级同时在线大型网络游戏:希望Online、问道的维护与运维工作。 https://ke.qq.com/teacher/57362523 https://www.imooc.com/qadetail/245958?t=561731#id_561731 必须是,听声音也听出来了; 再看一下,讲课内容和风格,100% 了; imooc的Tony老师 === 兄弟连的沈超老师 https://www.cnblogs.com/yongestcat/p/11736732.html https://zhuanlan.zhihu.com/p/345035621 https://www.icourse163.org/course/itxdl-1002597008 兄弟连教育成立于2006年,专注于软件开发技术培训,是PHP/LAMP技术培训学校,主营业务包括PHP培训、Java培训、安卓培训、软件开发、人才输出、教材出版、企业培训等。总部设在北京,在上海、广州、深圳、沈阳、石家庄、西安、武汉等城市都设有教学中心。 李超在信中表示,因公司现金流问题,即日起兄弟连北京校区停止招生,同时员工全部遣散。上海、广州校区已相继经独立运营,不再归属集团总部,可更换品牌正常开展业务。沈阳、西安校区业务、院校合作业务,相关负责人带领员工根据自身情况更换品牌可选择自行创业,自负盈亏。 其实,早在2019年底,兄弟连的资金状况就已经发生问题,最后的孤注一掷在学生寒假的线下营收上,可是此次疫情猛烈,政府通知线下培训业务暂停,成为压倒兄弟连的最后一根稻草。 “死撑不下去了”,李超在信中写明了疫情发生后的机构处境,“这对资金储备少,包袱重、一直亏损的兄弟连无疑是雪上加霜。节前咱们勒紧腰带,缓发工资、全体动员,压缩成本,就是为了节后招生旺季打个翻身仗。哪知这次疫情来的如此凶猛、猝不及防,把我们的计划全部打乱。” |
shelljs export bug$ shell.echo(shell.env.PATH);
|
"scripts": {
"dev": "cross-env NODE_OPTIONS='--max-old-space-size=8192' && npm run old_dev",
"old_dev": "cross-env NODE_ENV=development webpack-dev-server --inline",
"build": "rimraf dist && cross-env NODE_ENV=production webpack --progress --hide-modules",
"eslint": "eslint --fix --ext js,vue src",
"precommit": "lint-staged"
},
NODE_OPTIONShttps://nodejs.org/api/cli.html |
node js get system environment variablehttps://stackoverflow.com/questions/4870328/read-environment-variables-in-node-js process.env === process + envhttps://nodejs.org/api/process.html#process_process_env $ node -e 'process.env.foo = "bar"' && echo $foo
https://nodejs.dev/learn/how-to-read-environment-variables-from-nodejs ??? echo quickly blink bug ??? echo 一闪就消失了 ??? linux echo 一闪就消失了 http://www.bathome.net/thread-13418-1-1.html 批处理命令窗口闪一下就没了的原因: http://bbs.chinaunix.net/thread-1282392-1-1.html 不是看不见,是一闪而过 echo $foo;read a |
Linux Shell 脚本如何执行完毕之后不自动关闭窗口 写给前端的 shell 脚本编程详解 https://segmentfault.com/a/1190000037797344 https://developer.huawei.com/consumer/cn/forum/topic/0204414228553730437 |
cross-env usage bug单个 process 直接执行 ✅ "scripts": {
"dev": "cross-env NODE_OPTIONS='--max-old-space-size=8192' cross-env NODE_ENV=development webpack-dev-server --inline",
"build": "rimraf dist && cross-env NODE_ENV=production webpack --progress --hide-modules",
"eslint": "eslint --fix --ext js,vue src",
"precommit": "lint-staged"
}, cross-env NODE_OPTIONS='--max-old-space-size=8192' ❌
"scripts": {
"dev": "cross-env NODE_OPTIONS='--max-old-space-size=8192' && cross-env NODE_ENV=development webpack-dev-server --inline",
"build": "rimraf dist && cross-env NODE_ENV=production webpack --progress --hide-modules",
"eslint": "eslint --fix --ext js,vue src",
"precommit": "lint-staged"
}, // 单个 process 直接执行 ✅
command = `./node_modules/cross-env/dist/bin/cross-env.js ${key}='${env}' npm run dev`;
// command = `./node_modules/cross-env/dist/bin/cross-env.js ${key}='${env}' yarn dev`;
// && 多个 process ❌
// command = `./node_modules/cross-env/dist/bin/cross-env.js ${key}='${env}' && npm run dev`;
// command = `./node_modules/cross-env/dist/bin/cross-env.js ${key}='${env}' && yarn dev`; |
The Difference Between The Difference Between |
shell.exec bug
shell.exec not work
shelljs/shelljs#1048
Node version
ShellJS version
Operating system:
Description of the bug:
Example ShellJS command to reproduce the error:
test.js
The text was updated successfully, but these errors were encountered: