【问题标题】:MAC c++ control interactive Command Line ToolsMAC c++控制交互式命令行工具
【发布时间】:2012-09-29 02:41:53
【问题描述】:

我想从我的 c++ 代码中控制解压缩命令。我的问题是,如果我要解压缩的 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 命令行开关?
  • 到目前为止,我在这个网站上并不常见,抱歉。我会尽力而为,但我没有看到你发布了。

标签: c++ macos command-line interactive


【解决方案1】:

使用-P password 命令行开关将密码作为参数传递。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-24
    • 1970-01-01
    • 2014-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多