Solved executing bash commands with wildcards *
-
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 "
-
@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.
-
@bask185 Those are not wildcards.
You should put the whole path into "":"\"/media/user/name with spaces\""
-
@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.