从expect 脚本中,我调用另外两个shell 脚本。但只有第二个 shell 脚本似乎能正确执行。因为第一个shell脚本的输出语句在屏幕上是看不到的。这是我的期望脚本:
#!/usr/bin/expect
spawn /bin/bash test1.sh
spawn /bin/bash test2.sh
interact
Run Code Online (Sandbox Code Playgroud)
为什么会发生这种情况?解决办法是什么?
我有如下 NodeJS 代码:
[myFile.js]
var path = require("path");
var cp = require("child_process");
var child = cp.spawn( "python",["HelloWorld.py"], { stdio:'pipe', });
child.stdout.on('data', (data) => {
console.log(`CHILD stdout: ${data }`);
});
child.stderr.on('data', (data) => {
console.log(`CHILD stderr: ${data}`);
});
process.on("SIGINT",()=>{
// close gracefully
console.log("Received SIGINT");
})
child.on('exit',(code)=>{console.log(`child Process exited with code ${code}`)})
Run Code Online (Sandbox Code Playgroud)
和 python 脚本如下:
[HelloWorld.py]
print 'Hi there'
import time
time.sleep(5)
Run Code Online (Sandbox Code Playgroud)
我想优雅地管理关闭,但是当我通过以下方式在命令行启动此代码时:
> node myFile.js
Run Code Online (Sandbox Code Playgroud)
然后按 Control-C,我将其打印到控制台:
^CReceived SIGINT
CHILD stdout: Hi there
CHILD stderr: Traceback (most recent call last):
File …Run Code Online (Sandbox Code Playgroud) pm2 会在手表重启时杀死分离的子进程(即,这些子进程已经通过 detached:true、stdio:'ignore' 和 child.unref() 产生。
有没有办法告诉 pm2 在重启时不要杀死子进程树?
我有一个小问题......我想在我的场景中生成四边形,它们都应该有红色或绿色作为材质。但 Random.Range 函数只能 int\xc2\xb4s,我该如何解决它?
\n\nvoid SpawningSquadsRnd()\n {\n rndColor[0] = Color.red;\n rndColor[1] = Color.green;\n\n for (int i = 0; i < 5; i++)\n {\n GameObject quad = Instantiate(squadPrefab, new Vector3(Random.Range(- 23, 23), 1.5f, Random.Range(-23, 23)), Quaternion.identity);\n int index = Random.Range(0, rndColor.Length);\n\n quad.gameObject.GetComponent<Renderer>().material.color = //Random.Range(0, rndColor.Length);\n }\n }\nRun Code Online (Sandbox Code Playgroud)\n 我创建了一些代码来使用 node.js 后端的 python 函数。当在我的 ubuntu 计算机上运行它时,它可以工作 - 但是!当在他的 Windows 机器上运行代码时,它会给出这个堆栈跟踪。
events.js:174
throw er; // Unhandled 'error' event
^
Error: spawn python ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
at onErrorNT (internal/child_process.js:415:16)
at process._tickCallback (internal/process/next_tick.js:63:19)
at Function.Module.runMain (internal/modules/cjs/loader.js:757:11)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
Emitted 'error' event at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12)
at onErrorNT (internal/child_process.js:415:16)
[... lines matching original stack trace ...]
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
Run Code Online (Sandbox Code Playgroud)
这是node.js 文件
const spawn = require("child_process").spawn;
const pythonProcess = exec('python',["./script.py", 2, 4]);
pythonProcess.stdout.on('data', function(data) {
console.log(data.toString('utf-8'))
} )
Run Code Online (Sandbox Code Playgroud)
这是 …
尝试从node.js v12.6.0运行Windows批处理脚本并以正确的顺序实时捕获其输出。
但在测试过程中,stdout 和 stderr 的顺序经常(并非总是如此,但在 80% 的情况下)是混合的。
如何保持 stdout 和 stderr 的原始顺序?
这是我用于测试的 JavaScript 片段:
const spawn = require('child_process').spawn;
// Using 'inherit' to fix:
// "ERROR: Input redirection is not supported, exiting the process immediately".
const options = {
stdio: [
'inherit', // StdIn.
'pipe', // StdOut.
'pipe' // StdErr.
],
};
const child = spawn('exectest.cmd', options);
let mergedOut = '';
child.stdout.setEncoding('utf8');
child.stdout.on('data', (chunk) => {
process.stdout.write(chunk);
mergedOut += chunk;
});
child.stderr.setEncoding('utf8');
child.stderr.on('data', (chunk) => {
process.stderr.write(chunk);
mergedOut += …Run Code Online (Sandbox Code Playgroud) 我在 macOS 上工作,最近被 Python 3.8 多处理中的“fork”到“spawn”的变化所困扰(请参阅文档)。下面显示了一个简化的工作示例,其中使用“fork”成功,但使用“spawn”失败。代码的目的是创建一个支持size()在 macOS 下调用的自定义队列对象,从而继承该Queue对象并获取多处理的上下文。
import multiprocessing
from multiprocessing import Process
from multiprocessing.queues import Queue
from time import sleep
class Q(Queue):
def __init__(self):
super().__init__(ctx=multiprocessing.get_context())
self.size = 1
def call(self):
return print(self.size)
def foo(q):
q.call()
if __name__ == '__main__':
multiprocessing.set_start_method('spawn') # this would fail
# multiprocessing.set_start_method('fork') # this would succeed
q = Q()
p = Process(target=foo, args=(q,))
p.start()
p.join(timeout=1)
Run Code Online (Sandbox Code Playgroud)
使用“spawn”时输出的错误消息如下所示。
Process Process-1:
Traceback (most recent call last):
File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/process.py", line 315, in …Run Code Online (Sandbox Code Playgroud) 本周,我的一个标准 perl [Strawberry perl 5,版本 32,为 MSWin32-x64-多线程构建的 subversion 1 (v5.32.1)] 脚本开始失败。我追踪到失败的反引号操作。
调查显示,所有系统类型调用(反引号、qx、pipe open)均失败。我尝试构建 perl 的调试版本,但即使这样也失败了,因为构建过程使用 miniperl,它也有同样的问题。
..\miniperl.exe -I..\lib ..\make_ext.pl "MAKE=nmake -nologo" --dir=..\cpan --dir=..\dist --dir=..\ext - -nonxs
无法生成“cmd.exe”:在 ..\make_ext.pl 第 580 行没有这样的文件或目录。
无法生成“cmd.exe”:在 ..\make_ext.pl 行没有这样的文件或目录582.
make(dist/if) 失败:code=65280,位于 ..\make_ext.pl 第 584 行。
我尝试定义 PERL5SHELL(cmd 的完整路径,用 pwsh 代替 cmd),关闭恶意软件防护,以及我能想到的所有恢复。
所以,真正的问题是:有人对我如何追踪这个问题有建议吗?它在周四工作,此后没有系统更新[操作系统版本 10.0.22000]。
我尝试运行.sh文件时出错
line 2: spawn: command not found ": no such file or directory bash.sh: line 3: expect: command not found bash.sh: line 4: send: command not found
#!/usr/bin/expect -f
spawn sftp -o IdentityFile=MyFile.ppk 500200243@XXX.XXX.XXX.XXX
expect "XXX.XXX.XXX.XXX.gatewayEnter passphrase for key 'MyFile.ppk.ppk':"
send "myPassword"
Run Code Online (Sandbox Code Playgroud)
知道为什么会这样吗?
我正在尝试使用我已保存的图像创建缩略图.我正在使用该模块gm来调整图像的大小.
var gm = require ('gm');
var fs = require('fs');
var savedphoto = "./testphoto.jpeg";
var testdir = "./testoutput.jpeg";
gm(savedphoto)
.resize(100, 100)
.noProfile()
.write(testdir, function (err) {
console.error (err);
});
Run Code Online (Sandbox Code Playgroud)
当我运行这个时,我得到错误spawn ENOENT.
code: 'ENOENT', errno: 'ENOENT', syscall: 'spawn.
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?