回答編集履歴
2
コマンド修正
test
CHANGED
@@ -12,9 +12,13 @@
|
|
12
12
|
|
13
13
|
[task setLaunchPath:@"/bin/bash"];
|
14
14
|
|
15
|
+
// 以下のコマンドで管理者権限ユーザ名取得
|
16
|
+
|
15
17
|
[task setArguments:[NSArray arrayWithObjects: @"-c", @"dscl . -read /Groups/admin GroupMembership", nil]];
|
16
18
|
|
19
|
+
// 以下のコマンドでユーザ名取得
|
20
|
+
|
17
|
-
//[task setArguments:[NSArray arrayWithObjects: @"-c", @"u
|
21
|
+
//[task setArguments:[NSArray arrayWithObjects: @"-c", @"id -un", nil]];
|
18
22
|
|
19
23
|
|
20
24
|
|
1
実装方法修正
test
CHANGED
@@ -8,30 +8,32 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
NSTask *task = [[NSTask alloc] init];
|
11
|
+
NSTask *task = [[NSTask alloc] init];
|
12
12
|
|
13
|
-
|
13
|
+
[task setLaunchPath:@"/bin/bash"];
|
14
14
|
|
15
|
-
[task set
|
15
|
+
[task setArguments:[NSArray arrayWithObjects: @"-c", @"dscl . -read /Groups/admin GroupMembership", nil]];
|
16
16
|
|
17
|
-
[task setS
|
17
|
+
//[task setArguments:[NSArray arrayWithObjects: @"-c", @"users", nil]];
|
18
|
-
|
19
|
-
[task launch];
|
20
18
|
|
21
19
|
|
22
20
|
|
23
|
-
NS
|
21
|
+
NSPipe *pipe = [[NSPipe alloc] init];
|
24
22
|
|
25
|
-
|
23
|
+
[task setStandardOutput:pipe];
|
26
24
|
|
25
|
+
[task launch];
|
26
|
+
|
27
|
+
NSFileHandle *handle = [pipe fileHandleForReading];
|
28
|
+
|
29
|
+
NSData *data = [handle readDataToEndOfFile];
|
30
|
+
|
27
|
-
NSString *string = [[
|
31
|
+
NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
32
|
+
|
33
|
+
NSLog(string);
|
28
34
|
|
29
35
|
|
30
36
|
|
31
|
-
|
37
|
+
出力結果
|
32
38
|
|
33
|
-
|
34
|
-
|
35
|
-
[task release];
|
36
|
-
|
37
|
-
|
39
|
+
GroupMembership: root testuser
|