willmav5000 / freedcpp

Automatically exported from code.google.com/p/freedcpp
Other
0 stars 0 forks source link

Shell Output #17

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
RUS LANG:Здравствуйте! Хотелось бы увидеть 
реализацию этой функции в вашеи
клиенте. Спасибо!
ENG LANG: Hello! I would like to see the realization of this function in
vashei client. Thank you!

Original issue reported on code.google.com by konst.r...@gmail.com on 19 Jan 2010 at 3:17

GoogleCodeExporter commented 9 years ago
Жаль не шарую как работать с svn

Троль добавь в /linux/privatemessage.cc

else if (command == _("shell"))
                 {
                 string l=param;
                 const char *p; FILE *fp;
                 p=l.c_str();
                 char line[130];

                 fp = popen(p,"r");
                 fgets(line,sizeof line,fp);
                 pclose(fp);
                 typedef Func1<PrivateMessage, string> F1;
                 F1 *func = new F1(pm, &PrivateMessage::sendMessage_client, line);
                 WulforManager::get()->dispatchClientFunc(func);
                 }
и в linux/hub.cc

 else if (command == _("shell")){
                 string l=param;
                 const char *p; FILE *fp;
                 p=l.c_str();
                 char line[130];
                 fp = popen(p,"r");
                 fgets(line,sizeof line,fp);
                 pclose(fp);
                 func2 = new F2(hub, &Hub::sendMessage_client, line, false);
                 WulforManager::get()->dispatchClientFunc(func2);
        }

Original comment by peh...@gmail.com on 19 Jan 2010 at 8:08

GoogleCodeExporter commented 9 years ago
В релиз 0.0.2 данная команда /shell или /exec точно 
не войдёт может быть потом меня сейчас это 
мало волнует.

pehser, большое спасибо за код, но как то не 
есть хорошо.

Предлагаю сделать так (код не пытал 
возможны ошибки, если есть другие идеи 
пишите)...

if (command == "shell")
{
    if (!param.empty())
    {
        gchar *output = NULL;
        GError *error = NULL;

        g_spawn_command_line_sync(param.c_str(), &output, NULL, NULL, 
&error);

        if (error != NULL)
        {
            //TODO: вывод ошибки на GUI

            g_error_free(error);
        }
        else
        {
            string trash = output;
            g_free(output);

            func2 = new F2(hub, &Hub::sendMessage_client, trash, true/
*сообщение от 3-го лица*/);
            WulforManager::get()->dispatchClientFunc(func2);
        }
    }
}

даём команду в чате например /shell dcop amarok player 
nowPlaying

Остаётся только написать толковый скрипт 
для вывода более полной информации.

Original comment by troll.freedcpp@gmail.com on 21 Jan 2010 at 7:59

GoogleCodeExporter commented 9 years ago
Моя текущая реализация:

        else if (command == _
("exec"))
        {
            FILE *pipe = popen
( param.c_str(), "r" );
            gchar* cmd_result;
            gsize lennn = 0;
            GIOChannel* gioc = 
g_io_channel_unix_new(fileno(pipe));
            GIOStatus sttt = 
g_io_channel_read_to_end(gioc, &cmd_result, 
&lennn, NULL);
            if (sttt == 
G_IO_STATUS_NORMAL)
            {
                F2 *func = 
new F2( hub, &Hub::sendMessage_client, string
(cmd_result), true );
                WulforManager::get
()->dispatchClientFunc(func);
            }
            g_io_channel_close
(gioc);
            g_free(cmd_result);
            pclose(pipe);
        }

Может, чем-то поможет. Во всяком случае, 
работает, в том числе для многострочных 
выводов скриптов.

Original comment by ahmad200...@gmail.com on 22 Jan 2010 at 9:06

GoogleCodeExporter commented 9 years ago
если использовать функцию g_spawn_command_line_sync то 
не коретно работают команды
типа ls | grep br

Original comment by peh...@gmail.com on 28 Jan 2010 at 4:06

GoogleCodeExporter commented 9 years ago
это дыра

Original comment by mara.wor...@gmail.com on 7 Apr 2010 at 6:19

GoogleCodeExporter commented 9 years ago
реализовал вот это 
http://code.google.com/p/eiskaltdc/issues/detail?id=110
только все команды сразу отдаются шеллу.
может diff немного и корявый, но разберетесь.

Original comment by lelik...@gmail.com on 14 Apr 2010 at 10:27

Attachments:

GoogleCodeExporter commented 9 years ago
hi sorry but i dont talk russian did you resolve this issue ?

Original comment by lauriepa...@gmail.com on 9 Jun 2010 at 9:02