Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. echo redirect with QProcess
Forum Updated to NodeBB v4.3 + New Features

echo redirect with QProcess

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 3.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Shin.go
    wrote on last edited by
    #1

    Hi

    I want to use QProcess() with "echo".

    In terminal, $ echo "some out put" > test.txt , is OK.

    But, QProcess start("echo "some out put" > test.txt"), does not work.

    Finally, I want to call usb unbind/bind from Qt app.

    I want to run "echo "usb1" > /sys/bus/usb/drivers/unbind".

    Are there any solutions ?

    Best Regards,

    JonBJ 1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      QProcess != cmd/sh

      https://stackoverflow.com/questions/10701504/command-working-in-terminal-but-not-via-qprocess

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      1
      • S Shin.go

        Hi

        I want to use QProcess() with "echo".

        In terminal, $ echo "some out put" > test.txt , is OK.

        But, QProcess start("echo "some out put" > test.txt"), does not work.

        Finally, I want to call usb unbind/bind from Qt app.

        I want to run "echo "usb1" > /sys/bus/usb/drivers/unbind".

        Are there any solutions ?

        Best Regards,

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @Shin.go
        In your commands, it is the > output redirection symbol which is your problem. Only a shell (e.g. /bin/sh or /bin/bash) understands that symbol and what to do about it. You have two choices:

        • Handle the redirection to file yourself prior to calling QProcess or similar. Nicest, but most work.
          (EDIT: I see there is QProcess::setStandardOutputFile(const QString &fileName, OpenMode mode = Truncate). You could use this and remove your > text.txt from your command line, then your command should work without needing a shell to interpret the >. Note that it will use /bin/echo (or whatever is on your PATH) rather than a shell's built-in echo.

        • Make the whole of your command line into a single string to be handled by the shell, and do a QProcess of the shell with that as an argument. Untested by me, but something like:
          /bin/sh -c 'echo "some out put" > test.txt'

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved