| Summary: | set the working directory to the same directory as the executable when running an executable directly in konqueror | ||
|---|---|---|---|
| Product: | TDE | Reporter: | Whistler <whistler_wmz> |
| Component: | tdelibs | Assignee: | Timothy Pearson <kb9vqf> |
| Status: | RESOLVED FIXED | ||
| Severity: | minor | CC: | bugwatch, darrella |
| Priority: | P5 | ||
| Version: | 3.5.11 [Trinity] | ||
| Hardware: | All | ||
| OS: | Linux | ||
| Compiler Version: | TDE Version String: | ||
| Application Version: | Application Name: | ||
Uploaded to SVN in revision 1111449. Packages for Lucid should be automatically built by the end of the day. Thanks for reporting (and for the patch!) Patch still needs some cleanup apparently. Can you suggest a non-loop-based patch?
> On Monday 05 April 2010, Timothy Pearson wrote:
> > + for (QStringList::ConstIterator it = args.begin(); it != args.end();
> > ++it) + if (!(*it).contains('='))
> > + proc->setWorkingDirectory((*it).mid(0, (*it).findRev('/')));
>
> Why a loop?
>
> Exec=/foo/bar -e /tmp/blah
> will start in /tmp ?
>
> There's already a method to extract the binary name from the Exec line, better
> use that.
>
> --
> David Faure, faure@kde.org, http://www.davidfaure.fr
> Sponsored by Nokia to work on KDE, incl. Konqueror (http://www.konqueror.org).
Thanks!
well I think the KRun::binaryName() method only returns the filename of the binary rather than the full path, which could not be used here... e.g., returns "ls" for "AAAA=bbbb CCCC=dddd /bin/ls /usr/lib" I'm not really completely familiar with the code so I could be wrong though. (Comment #2) > Patch still needs some cleanup apparently. Can you suggest a non-loop-based > patch? > > > On Monday 05 April 2010, Timothy Pearson wrote: > > > + for (QStringList::ConstIterator it = args.begin(); it != args.end(); > > > ++it) + if (!(*it).contains('=')) > > > + proc->setWorkingDirectory((*it).mid(0, (*it).findRev('/'))); > > > > Why a loop? > > > > Exec=/foo/bar -e /tmp/blah > > will start in /tmp ? > > > > There's already a method to extract the binary name from the Exec line, better > > use that. > Exec=/foo/bar -e /tmp/blah
> will start in /tmp ?
oops, I got this wrong, sorry...
QStringList args = KShell::splitArgs( cmd );
for (QStringList::ConstIterator it = args.begin(); it != args.end(); ++it) {
if (!(*it).contains('=')) {
int pos = (*it).findRev('/');
if (pos != -1) {
proc->setWorkingDirectory((*it).mid(0, pos));
}
break;
}
}
d*mn, looks like I was stupid and did overlook the "removePath" parameter of KRun::binaryName() function...
sorry for that, hope I can get it correctly this time :)
QString bin = binaryName( cmd, false );
int pos = bin.findRev( '/' );
if (pos != -1) {
proc->setWorkingDirectory( bin.mid(0, pos) );
}
(Comment #3)
> well I think the KRun::binaryName() method only returns the filename of the
> binary rather than the full path, which could not be used here...
> e.g., returns "ls" for "AAAA=bbbb CCCC=dddd /bin/ls /usr/lib"
Uploaded to SVN in revision 1114572. |
currently trying to run an executable or script by double-click an executable in konqueror will not change the working directory for the executable, i.e., the program will run at the working directory of konqueror despite of where the executable/script itself is located. for example, cd /a/b/c/d/e /usr/bin/konqueror ...and any executable started within the opened konqueror window will have /a/b/c/d/e as working directory. This behavior doesn't allow simple running of many programs which are not distributed as rpm/deb packages but intended to extract & run directly, as well as many scripts which do something with the files within the working directory. Although it's possible to write a script or create a launcher, it would be annoying and not quite friendly. here's a patch to fix this: for kdelibs/kio/kio/krun.cpp: pid_t KRun::runCommand( const QString& cmd, const QString &execName, const QString & iconName ) { kdDebug(7010) << "runCommand " << cmd << "," << execName << endl; KProcess * proc = new KProcess; proc->setUseShell(true); *proc << cmd; KService::Ptr service = KService::serviceByDesktopName( binaryName( execName, true ) ); + QStringList args = KShell::splitArgs( cmd ); + for (QStringList::ConstIterator it = args.begin(); it != args.end(); ++it) + if (!(*it).contains('=')) + proc->setWorkingDirectory((*it).mid(0, (*it).findRev('/'))); return runCommandInternal( proc, service.data(), binaryName( execName, false ), execName, iconName ); }