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. How to execute command installed with snap
Forum Updated to NodeBB v4.3 + New Features

How to execute command installed with snap

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 534 Views 1 Watching
  • 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
    Stormbringer1900
    wrote on 23 Aug 2023, 20:12 last edited by Stormbringer1900
    #1

    On Ubuntu 20.04, when I try to execute something like :

    QProcess::execute("lpr ...");
    or
    system("lpr ...");

    That reply : lpr command not found.

    In gnome-terminal, the command lpr exists and "whereis lpr" reply in "/usr/bin"

    If I try QProcess::execute("whereis lpr"); there's no reply.

    No problem. I try this command : ls -l /usr/bin

    With gnome-terminale, I found a lot of files and lpr, lp and somes others files depending of snap installations.

    With QProcess and system, nothing from snap is present.

    Do you know why and what is the good way to execute a command installed by snap with QProcess or system, please ?

    J J C 3 Replies Last reply 23 Aug 2023, 20:19
    0
    • S Stormbringer1900
      23 Aug 2023, 20:12

      On Ubuntu 20.04, when I try to execute something like :

      QProcess::execute("lpr ...");
      or
      system("lpr ...");

      That reply : lpr command not found.

      In gnome-terminal, the command lpr exists and "whereis lpr" reply in "/usr/bin"

      If I try QProcess::execute("whereis lpr"); there's no reply.

      No problem. I try this command : ls -l /usr/bin

      With gnome-terminale, I found a lot of files and lpr, lp and somes others files depending of snap installations.

      With QProcess and system, nothing from snap is present.

      Do you know why and what is the good way to execute a command installed by snap with QProcess or system, please ?

      J Offline
      J Offline
      JoeCFD
      wrote on 23 Aug 2023, 20:19 last edited by JoeCFD
      #2

      @Stormbringer1900 you add the full path to it
      QProcess::execute("/usr/bin/lpr", QStringList() );

      QStringList arguments = { "lpr" };
      QProcess::execute("/usr/bin/lwhereis", arguments );

      1 Reply Last reply
      0
      • S Stormbringer1900
        23 Aug 2023, 20:12

        On Ubuntu 20.04, when I try to execute something like :

        QProcess::execute("lpr ...");
        or
        system("lpr ...");

        That reply : lpr command not found.

        In gnome-terminal, the command lpr exists and "whereis lpr" reply in "/usr/bin"

        If I try QProcess::execute("whereis lpr"); there's no reply.

        No problem. I try this command : ls -l /usr/bin

        With gnome-terminale, I found a lot of files and lpr, lp and somes others files depending of snap installations.

        With QProcess and system, nothing from snap is present.

        Do you know why and what is the good way to execute a command installed by snap with QProcess or system, please ?

        J Offline
        J Offline
        JonB
        wrote on 23 Aug 2023, 20:38 last edited by
        #3

        @Stormbringer1900
        Your snaps ought be in /snap/bin. You might want to put that on your PATH. Does that alter the behaviour?

        1 Reply Last reply
        0
        • S Stormbringer1900
          23 Aug 2023, 20:12

          On Ubuntu 20.04, when I try to execute something like :

          QProcess::execute("lpr ...");
          or
          system("lpr ...");

          That reply : lpr command not found.

          In gnome-terminal, the command lpr exists and "whereis lpr" reply in "/usr/bin"

          If I try QProcess::execute("whereis lpr"); there's no reply.

          No problem. I try this command : ls -l /usr/bin

          With gnome-terminale, I found a lot of files and lpr, lp and somes others files depending of snap installations.

          With QProcess and system, nothing from snap is present.

          Do you know why and what is the good way to execute a command installed by snap with QProcess or system, please ?

          C Offline
          C Offline
          ChrisW67
          wrote on 24 Aug 2023, 00:42 last edited by
          #4

          @Stormbringer1900 said in How to execute command installed with snap:

          QProcess::execute("lpr ...");

          QProcess::execute() takes a program name and a separate list of arguments. Since there is no executable named lpr ... this will fail.

          The non-Qt system() call passes the entire command string to a shell. If the shell cannot find the program after parsing the command then it either does not exists at all, or is not in the PATH of the launching process.

          If I try QProcess::execute("whereis lpr"); there's no reply.

          Same as above.

          With QProcess and system, nothing from snap is present.

          Then the relevant directory is not in the PATH inherited by your process. On my Ubuntu machine the /snap/bin directory is in the system-wide path.

          However, I do not see a connection between lpr and snap. On a generic Ubuntu machine lpr is a compatibility tool installed as a native application by CUPS:

          $ dpkg-query  -S /usr/bin/lpr
          cups-bsd: /usr/bin/lpr
          
          J 1 Reply Last reply 24 Aug 2023, 08:15
          1
          • C ChrisW67
            24 Aug 2023, 00:42

            @Stormbringer1900 said in How to execute command installed with snap:

            QProcess::execute("lpr ...");

            QProcess::execute() takes a program name and a separate list of arguments. Since there is no executable named lpr ... this will fail.

            The non-Qt system() call passes the entire command string to a shell. If the shell cannot find the program after parsing the command then it either does not exists at all, or is not in the PATH of the launching process.

            If I try QProcess::execute("whereis lpr"); there's no reply.

            Same as above.

            With QProcess and system, nothing from snap is present.

            Then the relevant directory is not in the PATH inherited by your process. On my Ubuntu machine the /snap/bin directory is in the system-wide path.

            However, I do not see a connection between lpr and snap. On a generic Ubuntu machine lpr is a compatibility tool installed as a native application by CUPS:

            $ dpkg-query  -S /usr/bin/lpr
            cups-bsd: /usr/bin/lpr
            
            J Offline
            J Offline
            JonB
            wrote on 24 Aug 2023, 08:15 last edited by
            #5

            @ChrisW67 said in How to execute command installed with snap:

            Then the relevant directory is not in the PATH inherited by your process. On my Ubuntu machine the /snap/bin directory is in the system-wide path.

            Which is as I wrote above.

            However, I do not see a connection between lpr and snap. On a generic Ubuntu machine lpr is a compatibility tool installed as a native application by CUPS:

            I agree, this has nothing to do with snap. It should be in /usr/bin. That should be on $PATH already.

            @Stormbringer1900 said in How to execute command installed with snap:

            If I try QProcess::execute("whereis lpr"); there's no reply.

            whereis itself is in /usr/bin/. If by any chance, somehow, /usr/bin is not on PATH then the whereis itself will fail to execute. What is the return result from QProcess::execute()? Did it write anything to stdout/err?

            Probably the first thing to try is

            echo $PATH
            # or possibly
            /bin/echo $PATH
            

            Compare calling via QProcess from Qt app against what it is in external shell where lpr etc. work.

            1 Reply Last reply
            1

            1/5

            23 Aug 2023, 20:12

            • Login

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