Skip to content

Commit

Permalink
debugging the invest subprocess call on Windows. fix natcap#47.
Browse files Browse the repository at this point in the history
  • Loading branch information
davemfish committed Oct 2, 2020
1 parent 19dc301 commit ddf6818
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "invest-workbench",
"productName": "InVEST Workbench",
"productName": "invest-workbench",
"version": "0.1.0-alpha",
"description": "My Electron application description",
"main": "src/main.js",
Expand Down
15 changes: 11 additions & 4 deletions src/InvestJob.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs';
import path from 'path';
import crypto from 'crypto';
import { spawn, execFile } from 'child_process';
import { spawn, exec } from 'child_process';
import React from 'react';
import PropTypes from 'prop-types';

Expand Down Expand Up @@ -185,21 +185,28 @@ export default class InvestJob extends React.Component {
`-d ${datastackPath}`,
];
// let investRun;
if (process.platform !== 'foo') {
if (process.platform !== 'win32') {
this.investRun = spawn(path.basename(investExe), cmdArgs, {
env: { PATH: path.dirname(investExe) },
shell: true, // without shell, IOError when datastack.py loads json
detached: true, // we want invest to terminate when this shell terminates
detached: true, // counter-intuitive, but w/ true: invest terminates when this shell terminates
});
this.investRun.terminate = () => {
if (this.state.jobStatus === 'running') {
process.kill(-this.investRun.pid, 'SIGTERM');
}
};
} else {
this.investRun = execFile(path.basename(investExe), cmdArgs, {
this.investRun = spawn(path.basename(investExe), cmdArgs, {
env: { PATH: path.dirname(investExe) },
shell: true,
});
this.investRun.terminate = () => {
if (this.state.jobStatus === 'running') {
exec(`taskkill /pid ${this.investRun.pid} /t /f`)
}
};
console.log(this.investRun)
}

// There's no general way to know that a spawned process started,
Expand Down

0 comments on commit ddf6818

Please sign in to comment.