![](/img/trans.png)
[英]C++ interactive command line prompt without waiting for a newline character
[英]MAC c++ control interactive Command Line Tools
我想从我的C ++代码中控制unzip命令。 我的问题是,如果要解压缩的ZIP文件是密码加密的,则解压缩工具会询问密码。
因此,我需要从我的c ++代码中为其提供密码,然后按Enter,但是我希望我的代码自动执行此操作。
所以这就是我到目前为止所得到的,但是当我运行它时,首先将执行system()命令,然后程序继续运行,但是在解压缩它时不会将密码写入终端:(
#include <iostream>
#include </System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/CoreGraphics.framework/Versions/A/Headers/CGEvent.h>
#include <Carbon/Carbon.h>
int main (int argc, const char * argv[])
{
using namespace std;
system("clear");
//----------------------------------------------
{
system("unzip /Users/das_virus/Desktop/NeuerOrdner2/M1/Auswahl.zip"),
cout << "a";
/*CGEventRef event1, event2, event3, event4;
event1 = CGEventCreateKeyboardEvent (NULL,(CGKeyCode)0,true);
event2 = CGEventCreateKeyboardEvent (NULL,(CGKeyCode)0,false);
event3 = CGEventCreateKeyboardEvent (NULL,(CGKeyCode)36,true);
event4 = CGEventCreateKeyboardEvent (NULL,(CGKeyCode)36,false);
ProcessSerialNumber psn;
GetFrontProcess(&psn);
CGEventPostToPSN(&psn,event1);
CGEventPostToPSN(&psn,event2);
CGEventPostToPSN(&psn,event3);
CGEventPostToPSN(&psn,event4);*/
}
return 0;
}
我希望有人能给我一个答案:)
使用-P password
命令行开关将密码作为参数传递。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.