|
@@ -140,49 +140,18 @@ ipcMain.on('docker-import', (event, filePath, tag) => {
|
|
|
|
|
|
|
|
|
ipcMain.on('generate-world', (event, {rosbag_path}) => {
|
|
|
-
|
|
|
- // 使用 spawn 启动脚本
|
|
|
- const serviceProcess = spawn('bash', ["/home/cicv/work/pji_desktop/simulation/run_map2gazebo.sh"], { detached: true });
|
|
|
-
|
|
|
- // 设置为后台进程
|
|
|
- serviceProcess.unref();
|
|
|
-
|
|
|
- // 监听输出
|
|
|
- serviceProcess.stdout.on('data', (data) => {
|
|
|
- console.log(`第一个脚本的输出: ${data}`);
|
|
|
- // 根据第一个脚本的输出判断其是否准备好
|
|
|
- if (data.toString().includes('Service map2gazebo started')) {
|
|
|
- startSecondScript();
|
|
|
+ const command = 'bash /home/cicv/work/pji_desktop/simulation/generate_world.sh ' + rosbag_path
|
|
|
+ console.log('World generation command:', command);
|
|
|
+ exec(command, (error, stdout, stderr) => {
|
|
|
+ if (error) {
|
|
|
+ console.error(`exec error: ${error}`);
|
|
|
+ event.reply('generate-world-response', { success: false, message: error.message });
|
|
|
+ } else {
|
|
|
+ console.log(`stdout: ${stdout}`);
|
|
|
+ console.error(`stderr: ${stderr}`);
|
|
|
+ event.reply('generate-world-response', { success: true, message: 'World generated successfully' });
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
- // 监听错误
|
|
|
- serviceProcess.stderr.on('data', (data) => {
|
|
|
- console.error(`执行第一个脚本时出错: ${data}`);
|
|
|
- });
|
|
|
-
|
|
|
- // 监听关闭
|
|
|
- serviceProcess.on('close', (data) => {
|
|
|
- console.log(`第一个脚本已关闭: ${data}`);
|
|
|
- });
|
|
|
-
|
|
|
- function startSecondScript() {
|
|
|
- // 启动第二个脚本
|
|
|
- const script2 = exec('bash /home/cicv/work/pji_desktop/simulation/play_rosbag.sh ' + rosbag_path, (error, stdout, stderr) => {
|
|
|
- if (error) {
|
|
|
- console.error(`执行第二个脚本时出错: ${error}`);
|
|
|
- event.sender.send('generate-world-result', { success: false, output: error });
|
|
|
- return;
|
|
|
- }
|
|
|
- console.log(`第二个脚本的输出: ${stdout}`);
|
|
|
-
|
|
|
- event.sender.send('generate-world-result', { success: true, output: stdout });
|
|
|
- });
|
|
|
-
|
|
|
- script2.on('exit', (code) => {
|
|
|
- console.log(`第二个脚本已退出,退出码: ${code}`);
|
|
|
- });
|
|
|
- }
|
|
|
});
|
|
|
|
|
|
|
|
@@ -219,12 +188,12 @@ ipcMain.on('start-container', (event, {zip_file_path, image_name, container_name
|
|
|
const script2 = exec(command, (error, stdout, stderr) => {
|
|
|
if (error) {
|
|
|
console.error(`执行第二个脚本时出错: ${error}`);
|
|
|
- event.sender.send('generate-world-result', { success: false, output: error });
|
|
|
+ event.sender.send('start-container-response', { success: false, output: error });
|
|
|
return;
|
|
|
}
|
|
|
console.log(`第二个脚本的输出: ${stdout}`);
|
|
|
|
|
|
- event.sender.send('start-container-result', { success: true, output: stdout });
|
|
|
+ event.sender.send('start-container-response', { success: true, output: stdout });
|
|
|
});
|
|
|
|
|
|
script2.on('exit', (code) => {
|