Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
*.iws
**/node_modules
node_modules
.idea
.idea
.vscode/
16 changes: 16 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var ChildProcess = require('child_process');
var IS_WIN = process.platform === 'win32';
var TableParser = require('table-parser');
var fs = require('fs');
/**
* End of line.
* Basically, the EOL should be:
Expand Down Expand Up @@ -273,6 +274,21 @@ function formatOutput(data) {
var ppid = ( d.PPID && d.PPID[0] ) || ( d.ParentProcessId && d.ParentProcessId[0] ) || undefined;

if (pid && cmd) {
// console.log('Print `%j`', cmd)
if (!IS_WIN && cmd.length > 1) {
// console.log('Print yes `%j`', cmd)
try {
cmd = fs.readFileSync('/proc/' + pid + '/cmdline', 'utf8').split('\0');
}
catch (err) {
if (err.code !== 'ENOENT') {
throw err;
}
}
// console.log('data: `%j`', data);
// cmd = fs.readFileSync('/proc/' + pid + '/cmdline').split('\0');
}

var command = cmd[0];
var args = '';

Expand Down
21 changes: 21 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var Path = require('path');
var Sinon = require('sinon');

var serverPath = Path.resolve(__dirname, './node_process_for_test.js');
var serverPathSpace = Path.resolve(__dirname, './with space/sleep with space.sh');
var UpperCaseArg = '--UPPER_CASE';
var child = null;
var pid = null;
Expand Down Expand Up @@ -197,3 +198,23 @@ describe('test', function () {
});
});
});

// don't run on Windows
(process.platform === 'win32' ? describe.skip : describe)('test command with space', function () {
before(function () {
child = CP.spawn(serverPathSpace);
pid = child.pid;
});

afterEach(killProcess);

it('by command with space in path', function (done) {
PS.lookup({pid: pid}, function (err, list) {
assert.equal(list.length, 1);
assert.equal(list[0].pid, pid);
assert.equal(list[0].command, '/bin/bash');
assert.equal(list[0].arguments[0], serverPathSpace);
done();
});
});
});
2 changes: 2 additions & 0 deletions test/with space/sleep with space
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
/bin/sleep 5
2 changes: 2 additions & 0 deletions test/with space/sleep with space.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
/bin/sleep 5