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. executing bash commands with wildcards *
Forum Updated to NodeBB v4.3 + New Features

executing bash commands with wildcards *

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.2k 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.
  • B Offline
    B Offline
    bask185
    wrote on 28 Jul 2017, 12:03 last edited by
    #1

    I am trying to let my Qt app execute certain bash commands, which works just not with wildcards.

    I need to import and export files from a usb stick to a directory in the home folder.

    The files all have similar names like W1.csv. To get them all I usually do W*.csv. For this I could work around it with the entryList() and a for-loop so this part is solve-able

    The second problem I'm having, is that I can't work around the different usb stick names. I can use the QDir functions and get the name of the usb stick, but the name contains spaces and that is a huge payne. For instance if I do

    cd /media/user/ /media/user/Ubuntu 16.04.2 LTS amd64
    // it won't work because I need to type 
    cd /media/user/Ubuntu\ 16.04.2\ LTS\ amd64/
    //this works but I can also do
    cd /media/user/"Ubuntu 16.04.2 LTS amd64"
    

    The problem with the quotes is that I cannot simply add them to the name because of weird things are happening to the string when I try.

    // This:
    if(usb->exists() == true) {
           QString tmp = usb->path();
           qDebug() << tmp;
    
    //returns
    /media/user/Ubuntu 16.04.2 LTS amd64 // no quotes
                ^                      ^
    

    I tried:

    QString tmp = "/media/user/";
     tmp += "\""; // '"', 34, '/"'
     tmp += "name with spaces";
     tmp += "\"";
    
     qDebug() << tmp; */  result /media/user/\"name with spaces\"  /*
    

    To execute the commands I used both system() and Qprocess but as long as I cannot feed these function a proper string......

    So I would like to know how I can use wild carts and/or how I can remove those pesky \ slashes in front of the "

    J 1 Reply Last reply 28 Jul 2017, 12:50
    0
    • B Offline
      B Offline
      bask185
      wrote on 31 Jul 2017, 08:44 last edited by
      #3

      @jsulm I don't need the entire path, only the part: "name with spaces". This is important because the bash cannot work with the spaces otherwise. An example of a terminal command would be:

      cp /media/user/"usb with a name"/text.txt /home/user/folder
      

      So in combination with process.start it has to be precisely:

      process.start("cp /media/user/"usb with a name"/text.txt /home/user/folder");
      

      But as we both know this does not compile. I also learned that the entire path can be encapsulated in quotes, that also works in the CLI. But I still have the problem that Qt adds the slashes. These slashes prevent me from running the command.

      However a solution just popped up. The lightbulb above my head shined so bright you might have noticed it :P
      Instead of launching the application directly I will launch it via a shellscript. And prior to launching the appliation the script will manually unmount the USB stick and then mount it again but with my own space-less name.

      I did this before with my raspberry system it had as purpose to apply updates. But with a little work I can repurpose that shellscript.

      1 Reply Last reply
      0
      • B bask185
        28 Jul 2017, 12:03

        I am trying to let my Qt app execute certain bash commands, which works just not with wildcards.

        I need to import and export files from a usb stick to a directory in the home folder.

        The files all have similar names like W1.csv. To get them all I usually do W*.csv. For this I could work around it with the entryList() and a for-loop so this part is solve-able

        The second problem I'm having, is that I can't work around the different usb stick names. I can use the QDir functions and get the name of the usb stick, but the name contains spaces and that is a huge payne. For instance if I do

        cd /media/user/ /media/user/Ubuntu 16.04.2 LTS amd64
        // it won't work because I need to type 
        cd /media/user/Ubuntu\ 16.04.2\ LTS\ amd64/
        //this works but I can also do
        cd /media/user/"Ubuntu 16.04.2 LTS amd64"
        

        The problem with the quotes is that I cannot simply add them to the name because of weird things are happening to the string when I try.

        // This:
        if(usb->exists() == true) {
               QString tmp = usb->path();
               qDebug() << tmp;
        
        //returns
        /media/user/Ubuntu 16.04.2 LTS amd64 // no quotes
                    ^                      ^
        

        I tried:

        QString tmp = "/media/user/";
         tmp += "\""; // '"', 34, '/"'
         tmp += "name with spaces";
         tmp += "\"";
        
         qDebug() << tmp; */  result /media/user/\"name with spaces\"  /*
        

        To execute the commands I used both system() and Qprocess but as long as I cannot feed these function a proper string......

        So I would like to know how I can use wild carts and/or how I can remove those pesky \ slashes in front of the "

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 28 Jul 2017, 12:50 last edited by
        #2

        @bask185 Those are not wildcards.
        You should put the whole path into "":

        "\"/media/user/name with spaces\""
        

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        3
        • B Offline
          B Offline
          bask185
          wrote on 31 Jul 2017, 08:44 last edited by
          #3

          @jsulm I don't need the entire path, only the part: "name with spaces". This is important because the bash cannot work with the spaces otherwise. An example of a terminal command would be:

          cp /media/user/"usb with a name"/text.txt /home/user/folder
          

          So in combination with process.start it has to be precisely:

          process.start("cp /media/user/"usb with a name"/text.txt /home/user/folder");
          

          But as we both know this does not compile. I also learned that the entire path can be encapsulated in quotes, that also works in the CLI. But I still have the problem that Qt adds the slashes. These slashes prevent me from running the command.

          However a solution just popped up. The lightbulb above my head shined so bright you might have noticed it :P
          Instead of launching the application directly I will launch it via a shellscript. And prior to launching the appliation the script will manually unmount the USB stick and then mount it again but with my own space-less name.

          I did this before with my raspberry system it had as purpose to apply updates. But with a little work I can repurpose that shellscript.

          1 Reply Last reply
          0

          1/3

          28 Jul 2017, 12:03

          • Login

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