Hi Adrian,
I'm working on some python files and I came up a way to take off file
input as would be done from a C++ program e.g.
off_util cube | script
script cube.off
script cube
Here is code sample from one script.
def open_off_file(tmp_dir, model, work_file):
# read from file argument or stdin. write a copy of off file in
temporary directory
off_file =
tmp_dir.name + "/off_file.off"
# try using the input file name or built in model name
if (model != ""):
ret = os.system("off_util %s > %s 2>/dev/null" % (model, off_file))
# if no file name was given or off_util failed try reading from
standard input
# will hang if nothing at standard input
if (model == "" or ret != 0):
fout = open(off_file, "w")
fout.writelines(sys.stdin.readlines())
fout.close()
# rename off_file.off to expected name
ret = os.system("mv %s %s/%s" % (off_file,
tmp_dir.name, work_file))
... then
# create temporary directory for input file
tmp_dir = tempfile.TemporaryDirectory()
open_off_file(tmp_dir, args.off_file, "tmp_base.off")
# change to temporary directory and work inside of it
os.chdir(
tmp_dir.name)
I don't mind working this way and I wouldn't change it now as it ends up
being easier, but originally I had tried to make temporary files.
On Cygwin Antiprism programs won't input or output anything in /tmp when
outside of /tmp.
A simple example is
off_util cube -o /tmp/cube.off (fails)
off_util cube > /tmp/cube.off (succeeds)
antiview /tmp/cube.off (fails)
but...
cd /tmp
off_util cube > cube.off (succeeds)
antiview cube.off (succeeds)
The umask which I have never changed is 022 (on ubuntu it is 007 maybe I
should tighten it). Changing the umask to permissive 000 didn't help.
Permission didn't matter.
I haven't found anything on this. Normal commands like cat /tmp/cube.off
work so it might be something weird about compiling in Cygwin. Maybe it
is time to cross compile in Ubuntu.
Note: I don't care if we don't find a fix to this as the above code
works ok.
Some further research... I put this code in util.cc
FILE *fopen_file(string &fpath)
{
backslash_to_forward(fpath);
system("ls -l /tmp/cube.off");
fprintf(stderr, "file = '%s'\n", fpath.c_str());
FILE *file = fopen(fpath.c_str(), "r");
if (file == NULL) {
fprintf(stderr, "fopen failed, errno = %d\n", errno);
}
if (file) {
struct stat st;
fstat(fileno(file), &st);
if (S_ISDIR(st.st_mode)) {
fclose(file);
file = nullptr;
}
}
return file;
}
The result of opening the file is here. Note that the first line is the
result of ls -l /tmp/cube.off so it exists. Something deeper is going on.
./antiview /tmp/cube.off
-rw------- 1 Roger Roger 571 May 28 21:05 /tmp/cube.off
file = '/tmp/cube.off'
fopen failed, errno = 2
-rw------- 1 Roger Roger 571 May 28 21:05 /tmp/cube.off
file = 'alt_names.txt'
fopen failed, errno = 2
-rw------- 1 Roger Roger 571 May 28 21:05 /tmp/cube.off
file = '/cygwin64/home/Roger/antiprism_rk/share/models/alt_names.txt'
-rw------- 1 Roger Roger 571 May 28 21:05 /tmp/cube.off
file = '/usr/local/share/antiprism/models/alt_names.txt'
fopen failed, errno = 2
antiview: error: could not open input file '/tmp/cube.off': not found
(or invalid)
Roger