|
1 | 1 | const { spawn } = require('child_process');
|
| 2 | +const { app } = require('electron'); |
| 3 | +const path = require('path'); |
| 4 | + |
| 5 | +async function setPATHEnv() { |
| 6 | + const puttyLookup = [ |
| 7 | + path.join(__dirname, 'dist', 'putty'), |
| 8 | + path.join(path.dirname(app.getPath('exe')), 'dist', 'putty') |
| 9 | + ]; |
| 10 | + |
| 11 | + // prevent adding duplicates |
| 12 | + let extra = [ |
| 13 | + ...puttyLookup, |
| 14 | + ].filter((dir) => { |
| 15 | + return process.env.PATH.indexOf(dir) < 0; |
| 16 | + }); |
| 17 | + extra.push(process.env.PATH); |
| 18 | + process.env.PATH = extra.join(";"); |
| 19 | +} |
2 | 20 |
|
3 | 21 | exports.openConsole = async (consoleRequest) => {
|
4 |
| - const genericConsoleCommand = 'xfce4-terminal --tab -T "%d" -e "telnet %h %p"'; |
| 22 | + // const genericConsoleCommand = 'xfce4-terminal --tab -T "%d" -e "telnet %h %p"'; |
| 23 | + const genericConsoleCommand = 'putty.exe -telnet %h %p -loghost "%d"'; |
| 24 | + |
5 | 25 | const command = prepareCommand(genericConsoleCommand, consoleRequest);
|
| 26 | + |
| 27 | + console.log(`Setting up PATH`); |
| 28 | + await setPATHEnv(); |
| 29 | + |
6 | 30 | console.log(`Starting console with command: '${command}'`);
|
7 | 31 |
|
8 | 32 | let consoleProcess = spawn(command, [], {
|
9 | 33 | shell :true
|
10 | 34 | });
|
11 | 35 |
|
12 | 36 | consoleProcess.stdout.on('data', (data) => {
|
13 |
| - console.log(`Console is producing: ${data.toString()}`); |
| 37 | + console.log(`Console stdout is producing: ${data.toString()}`); |
| 38 | + }); |
| 39 | + |
| 40 | + consoleProcess.stderr.on('data', (data) => { |
| 41 | + console.log(`Console stderr is producing: ${data.toString()}`); |
| 42 | + }); |
| 43 | + |
| 44 | + consoleProcess.on('close', (code) => { |
| 45 | + console.log(`child process exited with code ${code}`); |
14 | 46 | });
|
15 | 47 | }
|
16 | 48 |
|
|
0 commit comments