Results 1 to 14 of 14

Thread: Calling external programs via QProcess on Mac OS

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2009
    Location
    Berlin
    Posts
    14
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question Calling external programs via QProcess on Mac OS

    I'm quite new to MacOS and I'm trying to build my program on Mac OS for the first time. So far Windows and Linux were my target platforms. Everything works fine and I'm again impressed on the degree of platform independence that Qt offers.

    But there is one problem:

    I have a program (assume it's called foo) that attempts to call external tools (latex, gs) via QProcess. It should be quite straight forward and works fine on Windows and Linux


    Qt Code:
    1. QProcess process;
    2.  
    3. process.start("latex ......");
    4.  
    5. bool success = process.waitForStarted();
    6.  
    7. if(!success)
    8. {
    9. int error = process.error();
    10. qDebug("waitForStarted: error=%d\n", error);
    11. ....
    12. }
    To copy to clipboard, switch view to plain text mode 

    On Mac OS that simply doesn't work when I launched my application (foo) via the bundle file (foo.app). process.start() returns false and the error code is 0. But it works fine when I start foo via the executable that is inside the bundle under foo.app/Contents/MacOS/foo

    I notice that in that case a shell window pops up. Perhaps now it is executed in a different execution environment. Now foo can call all external tools.

    Assuming it is perhaps the PATH variable from the environment, I tried to add the required path entries to the process environment with

    Qt Code:
    1. QProcessEnvironment sysenv = QProcessEnvironment::systemEnvironment();
    2. QString path = sysenv.value("PATH");
    3. if(path != "")
    4. path += ":";
    5. path += "/usr/texbin:/usr/local/bin";
    6.  
    7. sysenv.remove("PATH");
    8. sysenv.insert("PATH", path);
    9.  
    10. process.setProcessEnvironment(sysenv);
    To copy to clipboard, switch view to plain text mode 

    It still doesn't work. Even if it would, I would prefer not messing around with PATH values. How can I get the same execution execution environment as in the shell? Do I have to wrap my call inside a script and execute that via "sh"?

    Why is a program started in a different context depending on whether the bundle or the exe from within the bundle is run?

    Google didn't really help on that.
    Last edited by berliner; 14th February 2011 at 21:54.

Similar Threads

  1. QProcess & Working with External Programs
    By jstippey in forum Qt Programming
    Replies: 2
    Last Post: 20th December 2010, 20:04
  2. [QProcess] Calling console program
    By bgarisn in forum Newbie
    Replies: 3
    Last Post: 25th February 2010, 15:11
  3. Calling external programs?
    By Hossie in forum Qt Programming
    Replies: 12
    Last Post: 17th May 2008, 17:19
  4. QProcess and console programs
    By bond_e in forum Qt Programming
    Replies: 10
    Last Post: 13th July 2007, 08:39
  5. How to communicate with external programs?
    By deekayt in forum Qt Programming
    Replies: 7
    Last Post: 27th October 2006, 23:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.