Results 1 to 3 of 3

Thread: Try to use QProcess

  1. #1
    Join Date
    May 2006
    Posts
    57
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Unhappy Try to use QProcess

    Hi, I'm try to do a simple tool in QT; this tool convert files from dos format to unix format, using tr program

    The I use a QProcess to comunicate tr with my program, but I failed to make it work, because in the error output ( readAllStandardError() ) say:
    "usage: tr [-Ccsu] string1 string2
    tr [-Ccu] -d string1
    tr [-Ccu] -s string1
    tr [-Ccu] -ds string1 string2"

    and the files are not modified...

    What is my mistake??

    The statement I am trying to use is:

    tr -d "\015" < DOS_File

    The code is this:
    Qt Code:
    1. QString prg,file;
    2.  
    3. td = new QProcess(this);
    4.  
    5. prg = "tr -d \"\\015\" < " + file;
    6. td->start(prg);
    To copy to clipboard, switch view to plain text mode 

    I have also tried to use this:

    Qt Code:
    1. QString file;
    2.  
    3. td = new QProcess(this);
    4.  
    5. inst<< "-d"<<"\"\\015\""<<"<"<<file;
    6. td->start("tr",inst);
    To copy to clipboard, switch view to plain text mode 

    I'm use QT 4.6 in mac

    Thanks
    Last edited by avis_phoenix; 2nd August 2010 at 20:19. Reason: spelling corrections

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Try to use QProcess

    Arguments are given separately
    http://doc.qt.nokia.com/4.6/qprocess.html#start

    Edit: hmm, ignore this reply of me, it's not correct.

  3. #3
    Join Date
    Jul 2010
    Posts
    21
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Try to use QProcess

    Note that "<" is not actually an argument to "tr", but a shell command that redirects the contents of a file to the application.

    You probably need two QProcesses - one for "cat file" (or something similar) and another for "tr options". Then redirect the output from "cat" to the input of "tr".

    Or make your application write a small script file for the given arguments, and execute the script with one single QProcess.

    Maybe there are other more elegant solutions.

    [edit] One more possibility: let the shell parse and execute your complete statement, e.g.
    Qt Code:
    1. td->start("sh -c \"tr -d \"\\015\" < " + file + "\"");
    To copy to clipboard, switch view to plain text mode 
    Last edited by hobbyist; 2nd August 2010 at 21:49.

  4. The following user says thank you to hobbyist for this useful post:

    avis_phoenix (3rd August 2010)

Similar Threads

  1. Qprocess
    By ricky in forum Newbie
    Replies: 1
    Last Post: 3rd August 2009, 09:32
  2. QProcess inside QProcess
    By bunjee in forum Qt Programming
    Replies: 7
    Last Post: 4th December 2008, 00:39
  3. QProcess in qt-2.3
    By winarko in forum Qt for Embedded and Mobile
    Replies: 7
    Last Post: 2nd July 2008, 21:58
  4. QProcess
    By agent007se in forum Newbie
    Replies: 10
    Last Post: 23rd July 2006, 01:11
  5. QProcess again ..
    By cmeliak in forum Qt Programming
    Replies: 13
    Last Post: 24th May 2006, 20:56

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.