Help with programming


I recently installed the Ubuntu subsystem onto win10. It isn’t full-featured or up-to-date, so I have to install and build software, which I don’t like due to the lack of experience and talent. I feel like I am thrashing in the dark, brute forcing my way until something happens. Very time consuming.

Anyway, I have decided to make a thread where I shall ask questions from time to time. Others may do so as well. :wink: Not all of us are pros, right?

First question:
Several years ago, I hacked a *.cpp file to save an image. I know nothing about c++ but found something that worked using boost’s filesystem. Now it doesn’t (due to a different version?).

path p{argv[i]};
path sdir{p.parent_path().string() + "/DET/" + p.stem().string() + ".png"};
path d{p.parent_path().string() + "/DET/"};
cout << p.filename().string() << '\n' << endl;
if (tile_images(chips).size() != 0)
    save_png(tile_images(chips), sdir.string());
    save_png(img, sdir.string());

My intention is to create a new sub-directory where the output files would go. Currently, it is trying to save to /DET/ (at root) instead. What should I do? Should I even be using boost?

(Gord) #2

This line:

suggests that a path name is supposed to be passed to the program as an argument. Not knowing the value of i it’s not possible to say which of possibly several arguments it is. It would help if you showed the entire program.


I am here: /mnt/x/_px.   argv[i] is the input file at /mnt/x/_px/input.png.   Saving to /DET/output.png instead of /mnt/x/_px/DET/output.png

I know what the problem is now. I didn’t type “./” before output.png. In win10, I don’t have to do that.


This is a G’MIC related question but the content itself is more general. I would like to use this following command within user.gmic but don’t know how to escape properly.

load_gmic C:\Users\afre\AppData\Roaming\0.gmic

[gmic]-0./ *** Warning *** File ‘C:UsersafreAppDataRoaminguser.gmic’ is not a valid G’MIC command file.

Edit: maybe it is G’MIC specific. I will ping @David_Tschumperle.

(David Tschumperlé) #5

Several suggestions :

  1. Try using slashes instead of backslashes in the path
  2. Double your backslashes:
load_gmic C:\\Users\\afre\\AppData\\Roaming\\0.gmic


  1. Use the {/string} substitution mechanism to automatically escape the backslashes (so it is equivalent to doubling the backslahes):
load_gmic  {/"C:\Users\afre\AppData\Roaming\0.gmic"}

The reasons is that a backslash in a string acts as a special character (as in C), so it needs to be doubled to actually represent a single backslash.

Foreground extraction (command line)

I tried 1. and 2. and now 3. I still get the warning.

(Glenn Butcher) #7

What shell are you using?


cmd.exe. It should not matter though since it is going through the gmic interpreter. The *.gmic files are UTF-8.

(Glenn Butcher) #9

2a: So, I think you need an backslash escape that cmd.exe doesn’t care about so it survives getting to G’MIC. Try slngle-quoting the path, and double up the backslashes.


Like this → load_gmic 'C:\\Users\\afre\\AppData\\Roaming\\0.gmic'? I tried double quoting before as well.

The reason for this line of inquiry is that my user.gmic is getting too unwieldy and messy to manage. I would like to divide it into manageable chunks and name them according to purpose.

(Glenn Butcher) #11

My thought was cmd.exe was handling the escaped ‘’, and G’MIC was ending up with this\that, and getting rid of the \t and such, but I just went and re-read about quoting in cmd.exe and now I just don’t know anything good… :smile:

Shell scripting in Windows is goofy. Powershell has promise, but I haven’t used it enough to see consistent patterns like I do with the Unix shells.


The thing is that it is within the *.gmic file, so the rules of cmd.exe may not apply. However, when you are talking about paths, now you are accessing something on the outside. I think that is where the trouble lies. Or I am just missing the obvious. :blush:

This is what I have.


#@gmic user

#up2 :
load_gmic {/"C:\Users\afre\AppData\Roaming\0.gmic"}

#too much stuff

#@gmic _


#@gmic 0

  echo[] "Hello! :)"

#@gmic _


Could someone with Windows (I have win10) confirm this load_gmic issue? If it works for you, what did you do differently?


What/where is the definition of “load_gmic”? What exactly are you trying to do?

This worked for me on win7:

# Path of this file: c:\Users\garagecoder\AppData\Roaming\user.gmic
testloadfile : m "c:\Users\garagecoder\AppData\Roaming\0.gmic"


# Path of this file: c:\Users\garagecoder\AppData\Roaming\0.gmic
hello : e "Hello! :)"

cmd output:

gmic testloadfile hello
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./testloadfile/ Import commands from file 'c:\Users\garagecoder\AppData\Roaming\0.gmic' (1 
new, total: 3148).
[gmic]-0./hello/ Hello! :)
[gmic]-0./ End G'MIC interpreter.

Edit: I understand the purpose now - basically split up the user file into parts, but still load them all automatically. I’m not sure that’s possible because the script files define commands rather than actually execute them…

Perhaps @David_Tschumperle can advise - is there an equivalent to an #include for gmic command files?


Yes, that is exactly what I am looking for.