Skip to content

Commit d737eb6

Browse files
Merge pull request #119 from telerik/vladimirov/fix-get-pid
fix: getPid returns incorrect result
2 parents 0cd1776 + be7e61d commit d737eb6

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/iphone-simulator-xcode-simctl.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,14 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
108108
}
109109

110110
private getPid(deviceId: string, bundleExecutable: string): string {
111-
return childProcess.execSync(`ps -ef | grep ${bundleExecutable} | grep ${deviceId} | grep -v grep | awk '{print $2}'`, { skipError: true }).toString().trim();
112-
}
111+
// Sample output of the command ps -ef | grep app3grep | grep /86DCBE59-7ED0-447D-832B-A397322BD712/
112+
// 1203284766 59345 51524 0 7:11pm ?? 0:01.32 /Users/username/Library/Developer/CoreSimulator/Devices/86DCBE59-7ED0-447D-832B-A397322BD712/data/Containers/Bundle/Application/4E79A7E8-9AAB-40B9-89EF-C8D7B91B819E/app3grep.app/app3grep
113+
// 1203284766 59486 59396 0 7:15pm ?? 0:00.01 /bin/sh -c ps -ef | grep app3grep | grep /86DCBE59-7ED0-447D-832B-A397322BD712/
114+
// The process, that is execed by Node.js is also returned, so we need to exclude it from the result.
115+
// To achieve this, remove the command we've executed from the ps result.
116+
const grepAppProcessCommand = `ps -ef | grep ${bundleExecutable} | grep \/${deviceId}\/`;
117+
return childProcess.execSync(`${grepAppProcessCommand} | grep -v "${grepAppProcessCommand}" | awk '{print $2}'`, { skipError: true }).toString().trim();
118+
}
113119

114120
public async getDeviceLogProcess(deviceId: string, predicate?: string): Promise<child_process.ChildProcess> {
115121
const device = await this.getDeviceFromIdentifier(deviceId);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ios-sim-portable",
3-
"version": "4.0.6",
3+
"version": "4.0.7",
44
"description": "",
55
"main": "./lib/ios-sim.js",
66
"scripts": {

0 commit comments

Comments
 (0)