This forum has been archived. All content is frozen. Please use KDE Discuss instead.

[SOLVED] Shell script from KDE app

Tags: None
(comma "," separated)
salahuddin66
Registered Member
Posts
4
Karma
0
OS

[SOLVED] Shell script from KDE app

Wed May 27, 2009 3:38 am
Dear all,

I have written a small application "simpleAddOn" to install packages in Linux mainly for the newbie users.
Code: Select all
   if(packageOption == "multimedia") {
      run_result = system("kdesudo -c 'sh scripts/multimedia.sh'");
   }

multimedia.sh
Code: Select all
#!/bin/bash
dpkg -i deb/multimedia/*.deb


If I run the GUI application from terminal in Kubuntu 9.04 ./simpleAddOn then it run the script and install packages without any problem.

but if I open the GUI by clicking on simpleAddOn then it did not run the script. Any other idea of installing packages or hints ?

Screenshots:
http://picasaweb.google.com/lh/photo/hR ... directlink

I have written similar app for Ubuntu 0.04 in GTK working fine for both cases.
Code: Select all
if(!strcmp(data, "multimedia"))
    {
   g_print("multimedian");
        run_result = system("gksu -d 'sh scripts/multimedia.sh'");
    }
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

[SOLVED] Shell script from KDE app

Wed May 27, 2009 6:07 am
Qt/KDE applications should use QProcess to execute external applications.
Code: Select all
QProcess::startDetached( QString )
QString = command including parameters


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
anda_skoa
KDE Developer
Posts
783
Karma
4
OS

[SOLVED] Shell script from KDE app

Wed May 27, 2009 4:28 pm
Check the environment.

An interactive shell in the terminal can have a different environment than the shell running the startkde script.

Cheers,
_


anda_skoa, proud to be a member of KDE forums since 2008-Oct.
User avatar
Ignacio Serantes
Registered Member
Posts
453
Karma
1
OS

[SOLVED] Shell script from KDE app

Wed May 27, 2009 6:46 pm
Check this entry because could be useful for you:

currentpath-doesnt ... l#pid77360

As I can see you use relative path when you really don't know where you are. As I write in the other post is not a good idea.


Ignacio Serantes, proud to be a member of KDE forums since 2008-Nov.
salahuddin66
Registered Member
Posts
4
Karma
0
OS

[SOLVED] Shell script from KDE app

Wed May 27, 2009 7:31 pm
I have tried with QProcess::execute. I am already using QThread one for progress bar and another for installing.

Code: Select all
   QString program = "kdesudo";
      QStringList arguments;
           arguments << "-c" << "./scripts/internet.sh";
      run_result = QProcess::execute(program,arguments);


also tried with QProcess::startDetached( QString )

Same problem it is okey from shell but if I click, GUI appears but unable to install packages. (I have also checked the file permission).

Is there anyway to call dpkg -i deb/internet/*.deb ?
What kpackagekit or other installer software use to install ?
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

[SOLVED] Shell script from KDE app

Thu May 28, 2009 6:23 am
You should probably call KDESudo with the full path to the shell script, not one dependent on your current directory.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
salahuddin66
Registered Member
Posts
4
Karma
0
OS

[SOLVED] Shell script from KDE app

Thu May 28, 2009 3:24 pm
Yes I have checked that but still same problem.
Now I am trying to figure our how other KDE package manager install packages.
salahuddin66
Registered Member
Posts
4
Karma
0
OS

[SOLVED] Shell script from KDE app

Fri May 29, 2009 7:53 am
At last it worked with system() function with full path thanks to @bcooksley


//run_result = system("kdesudo -c 'dpkg -i /home/salahuddin/deb/internet/*.deb'");
Code: Select all
 QString execute1 = "kdesudo -c 'dpkg -i ";
    QString appPath = QApplication::applicationDirPath();
    appPath.prepend(execute1);
         QString execute2 = "/deb/internet/*.deb'";        
    appPath.append(execute2);
    run_result = system(appPath.toAscii());



But it did not worked for me
Code: Select all
    QString program = "kdesudo";
         QStringList arguments;
          arguments isSet("c"))
      {
         QString command = args->getOption("c");
         cmd += command;
         *p << "sh";
         *p << "-c";
         *p << command;
      }



kpPty.h in Kpackage
Code: Select all
 kpKProcIO ( QTextCodec *_codec = 0);
  QStringList  run(const QString &cmd, bool inLoop = true,
         bool needRoot= false, bool noReturn = false);


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]