Bug: cannot use "~" in path. calls fail.
05 May 2013 00:55 #33611
by zarthcode
Bug: cannot use "~" in path. calls fail. was created by zarthcode
Okay, I'm just about done with my mill upgrades. Just one more oddity that doesn't seem to jive with the docs.
I have a couple directories that store files
~/linuxcnc/mfiles (in the m path)
~/linuxcnc/subs (in the subroutine path, where I'm having an issue, atm)
~/linuxcnc/ncfiles (this is the program_prefix directory)
~/linuxcnc/ncfiles/ngcgui_lib (also an issue)
~/linuxcnc/ncfiles/ngcgui_lib/utilitysubs
~/linuxcnc/ncfiles/
In my display:
PROGRAM_PREFIX = /home/anthony/linuxcnc/ncfiles
In my [RS274NGC]:
SUBROUTINE_PATH = ~/linuxcnc/subs:~/linuxcnc/ncfiles/ngcgui_lib:~/linuxcnc/ncfiles/ngcgui_lib/utilitysubs
USER_M_PATH = ~/linuxcnc/mfiles:~/linuxcnc/ncfiles/ngcgui_lib/mfiles
Both Axis/NGCGUI can load files from all my paths. However, When I finalize and attempt to load auto.ngc, I get a complaint that and subroutines not located in the program prefix (ncfiles) cannot open file <name here>.
Switching each path from ~ to /home/anthony fixed those issues.
I have a couple directories that store files
~/linuxcnc/mfiles (in the m path)
~/linuxcnc/subs (in the subroutine path, where I'm having an issue, atm)
~/linuxcnc/ncfiles (this is the program_prefix directory)
~/linuxcnc/ncfiles/ngcgui_lib (also an issue)
~/linuxcnc/ncfiles/ngcgui_lib/utilitysubs
~/linuxcnc/ncfiles/
In my display:
PROGRAM_PREFIX = /home/anthony/linuxcnc/ncfiles
In my [RS274NGC]:
SUBROUTINE_PATH = ~/linuxcnc/subs:~/linuxcnc/ncfiles/ngcgui_lib:~/linuxcnc/ncfiles/ngcgui_lib/utilitysubs
USER_M_PATH = ~/linuxcnc/mfiles:~/linuxcnc/ncfiles/ngcgui_lib/mfiles
Both Axis/NGCGUI can load files from all my paths. However, When I finalize and attempt to load auto.ngc, I get a complaint that and subroutines not located in the program prefix (ncfiles) cannot open file <name here>.
Switching each path from ~ to /home/anthony fixed those issues.
Please Log in or Create an account to join the conversation.
05 May 2013 01:19 #33614
by BigJohnT
Replied by BigJohnT on topic Bug: cannot use "~" in path. calls fail.
~ is in the Linux world a representation for /home/computername sorry for the confusion. I tried to eliminate all of them. Where did you see them in the manuals? A link to the html or the page number of the PDF will help.
John
John
Please Log in or Create an account to join the conversation.
05 May 2013 02:11 #33615
by dgarrett
Replied by dgarrett on topic Bug: cannot use "~" in path. calls fail.
tilde expansion for ini entries like:
[RS274NGC]SUBROUTINE_PATH
and
[RS274NGC]USER_M_PATH
became available for git-master with commits like:
git.linuxcnc.org/gitweb?p=linuxcnc.git;a...4b49af684a6983629574
git.linuxcnc.org/gitweb?p=linuxcnc.git;a...65b1f829ffda0548f0ce
(so not available with current 2.5.2 or earlier)
[RS274NGC]SUBROUTINE_PATH
and
[RS274NGC]USER_M_PATH
became available for git-master with commits like:
git.linuxcnc.org/gitweb?p=linuxcnc.git;a...4b49af684a6983629574
git.linuxcnc.org/gitweb?p=linuxcnc.git;a...65b1f829ffda0548f0ce
(so not available with current 2.5.2 or earlier)
Please Log in or Create an account to join the conversation.
05 May 2013 04:36 #33625
by BigJohnT
Replied by BigJohnT on topic Bug: cannot use "~" in path. calls fail.
I hope someone documented that in master...
John
John
Please Log in or Create an account to join the conversation.
05 May 2013 08:13 #33635
by andypugh
Replied by andypugh on topic Bug: cannot use "~" in path. calls fail.
The explanation is probably that LinuxCNC thinks it is root, not you, so the ~ won't expand to your home directory.Switching each path from ~ to /home/anthony fixed those issues.
Please Log in or Create an account to join the conversation.
05 May 2013 19:06 - 05 May 2013 23:23 #33651
by ArcEye
Replied by ArcEye on topic Bug: cannot use "~" in path. calls fail.
Hi
Expansion of the tilde symbol does not happen in several cases, it can be a pain.
I have had to put in specific paths in just the same situation as you.
As well as the case you mentioned, using a string like "~/test.txt" to write a file can sometimes create a directory '~' in the current working directory, with the file test.txt inside it, not what was intended!
EDIT: (didn't explain why)
The crux of the problem is that the tilde expansion is something bash does, so does not work outside of that environment.
C libraries have no idea what it is, so system("echo 123456789 > ~/myhome.txt"); will probably work whereas fptr = fopen("~/myhome.txt", w); fwrite(fptr,"123456789"); will not.
To reliably get the home directory of the current user in C programs, you need to get the password struct and get homedir from that
#include <pwd.h>
struct passwd *pw = getpwuid(getuid());
const char *homedir = pw->pw_dir;
The environment variable HOME is generally available and in a lot of cases (certainly in scripts) the string
$HOME/linuxcnc/ncfiles will work instead of ~/linuxcnc/ncfiles for example
Try echo $HOME in a terminal and it should show your home dir
regards
Expansion of the tilde symbol does not happen in several cases, it can be a pain.
I have had to put in specific paths in just the same situation as you.
As well as the case you mentioned, using a string like "~/test.txt" to write a file can sometimes create a directory '~' in the current working directory, with the file test.txt inside it, not what was intended!
EDIT: (didn't explain why)
The crux of the problem is that the tilde expansion is something bash does, so does not work outside of that environment.
C libraries have no idea what it is, so system("echo 123456789 > ~/myhome.txt"); will probably work whereas fptr = fopen("~/myhome.txt", w); fwrite(fptr,"123456789"); will not.
To reliably get the home directory of the current user in C programs, you need to get the password struct and get homedir from that
#include <pwd.h>
struct passwd *pw = getpwuid(getuid());
const char *homedir = pw->pw_dir;
The environment variable HOME is generally available and in a lot of cases (certainly in scripts) the string
$HOME/linuxcnc/ncfiles will work instead of ~/linuxcnc/ncfiles for example
Try echo $HOME in a terminal and it should show your home dir
regards
Last edit: 05 May 2013 23:23 by ArcEye.
Please Log in or Create an account to join the conversation.
07 May 2013 22:10 #33731
by zarthcode
Replied by zarthcode on topic Bug: cannot use "~" in path. calls fail.
Offending entries are at: linuxcnc.org/docs/html/gui/ngcgui.html
There's some emc2 references, also.
There's some emc2 references, also.
Please Log in or Create an account to join the conversation.
Time to create page: 0.166 seconds