问题描述
我想在 Cocoa 中使用命令行来记录一堆密钥中的密码。 但我不能在行中插入变量。如何制作?
$pass 如何为我提供 self.PassKey?
self.PassKey = [_PassTextField stringValue];
NSTask *taskPass = [[NSTask alloc] init];
[taskPass setLaunchPath:@"/bin/bash"];
[taskPass setArguments:[NSArray arrayWithObjects: @"-c",@"/usr/bin/security delete-generic-password -a ${USER} -s post | security add-generic-password -a ${USER} -s post -w $pass",nil]];
[taskPass launch];
感谢您的帮助!
感谢大家的帮助和如此及时的回复!
如此有效:
self.PassKey = [_PassTextField stringValue];
NSLog(@"text changed: %@",self.PassKey); ///I printed in a window the password 12345
NSString * command = [NSString stringWithFormat:@"/usr/bin/security delete-generic-password -a ${USER} -s post | security add-generic-password -a ${USER} -s post -w %@",self.PassKey]; ///I receive a line /usr/bin/security delete-generic-password -a ${USER} -s postftp | security add-generic-password -a ${USER} -s postftp -w 12345
NSLog(@"command line: %@",command);
NSTask *taskPass = [[NSTask alloc] init];
[taskPass setLaunchPath:@"/bin/bash"];
[taskPass setArguments:[NSArray arrayWithObjects: @"-c",command,nil]];
[taskPass launch];
在一堆密钥结果中记录密码。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)