@无名啊,加上
shopt -s expand_aliases
可以了 谢谢大佬。只是,这nodejs代码里,哪一行是代表连接到了tty吗?(我不熟悉nodejs,但我还是能看得懂很多js的,即使是到ES2022)
我的理解跟编程语言无关,我是fork出来的子进程来启动bash命令,这个bash命令不会立刻退出,可以等待我输入,我就可以输入流写入数据,我称它为“交互式” 😂(1. 也可能默认开启了tty 2.也可能没有收到终止信号,所以一直等待)
和实际 交互式登录SHELL 非交互式登录SHELL概念是否一样,我并没有仔细研究
@无名啊,好的,谢谢。我明天试试10楼的。
你写的那个参数,我之前查资料是bash这个shell才有的好像。zsh好像没有
shopt is not a command, but a shell built-in. bash knows what to do with it because it's a bash built-in , but zsh has no idea what it is. You'll want to look into setopt which is a zsh built-in, and put those values into a new .zshrc script.
@无名啊,shopt 这个软件我电脑没有。。
22:50 测试发现,原来是我用的zsh没有。我没具体看这个报错,我明天再试试
shopt is not a command, but a shell built-in. bash knows what to do with it because it's a bash built-in , but zsh has no idea what it is. You'll want to look into setopt which is a zsh built-in, and put those values into a new .zshrc script.
@无名啊,我是python2 2>file.err 这么测试的,sed我是不太会用
@无名啊,我知道7楼这个方案,因为机器没网,电脑里没有这个软件。所以就没采用这个。。。
使用的交互式shell,是不好用的。
然后,我是拿python2.7测试--version输出到错误流的(我还没测试其他机器的2.7是否也这样)
@无名啊,以Node.js 创建子进程为例
import * as child from 'child_process' export async function execRequest(cmd: string, commands: string[]) { return new Promise((resolve) => { let spawnChild = child.spawn(cmd) spawnChild.stdout.on('data', ch => { console.log(ch.toString().trim()) }) spawnChild.stderr.on('data', ch => { console.log(ch.toString().trim()) }) spawnChild.on('exit', code => { console.log(code) }) commands.forEach((command) => { spawnChild.stdin.write(`${command}\n`) }) spawnChild.stdin.end('\nexit\n') }) } await execRequest('bash',['alias python233=python2','python233 --version 2>&1'])
以上代码 大概意思是,输入bash,并开启交互式shell
第一次流写入alias python233=python2 并且回车
第二次流写入python233 --version 2>&1 并且回车
输出流提示
提示python233不存在
PS: python --version竟然输出到错误流 真离谱
@无名啊,是的 因为我是子进程打开的shell 我无法做到输入两条命令,因为我不是在tty下进行输入的
@无名啊,抱歉 我不是用我举得例子测试的。我现在明白了,不加引号,是参数没有携带。并且会提示alias 没有ll参数
现在明白你引用的大意了,所以我补充了我的需求场景,明白alias不符合我的要求了
并不行哦
ubuntu@ubuntu:~$ alias lll='ls-ll';lll
Command 'lll' not found, did you mean:
command 'llc' from deb llvm
command 'dll' from deb brickos
command 'llt' from deb storebackup
command 'lli' from deb llvm-runtime
Try: sudo apt install <deb name>
@泰戈尔会游泳,是城里人会玩,生活成本高,知道都是韭菜。农村有一定自主权,自建房啥的 生活成本也相对低一些
@MINE,城镇是这样的,不敢生。农村落后思想的还是喜欢生吧。。。(当然,是我的猜想)
@o,因为你在城里,村里屯里封建思想的地方不一定这样
elk分词吗
不可能,那是你卡了。redis内存读的
@老虎会游泳,为什么你艾特的颜色和我的不一样
@嚻,@嚻,@嚻,@嚻,@嚻,@嚻,
你这个除非出问题了,我没有收到消息
@cnhong,http://www.hostloc.com/forum.php?mod=viewthread&tid=409176
@堂妹妹的,http://www.hostloc.com/forum.php?mod=viewthread&tid=409176
别用免费空间了,现在黑五一年才一刀