discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

is there a way to write generic text to an output file?

JD
John David
Mon, Feb 10, 2025 10:56 PM

I want to write some generic text (similar to echo statements) to a user
defined output file.  My interest in this is to use it in conjunction with
the timing tests to output the results from dozens of tests.  In the past,
I have used stuff like this to output the configuration of a simulation, so
I know what all the parameters were.

I see in the GitHub issues "Allow OpenSCAD to open and write out text files
#3400" https://github.com/openscad/openscad/issues/3400 that some folks
were looking to use the same functionality to be able to output their CAM
G-Code.

Was this functionality ever implemented?  If so, where/how?

If not, are there any objections to me implementing something like this and
requesting a PR?

EBo --

I want to write some generic text (similar to echo statements) to a user defined output file. My interest in this is to use it in conjunction with the timing tests to output the results from dozens of tests. In the past, I have used stuff like this to output the configuration of a simulation, so I know what all the parameters were. I see in the GitHub issues "Allow OpenSCAD to open and write out text files #3400" <https://github.com/openscad/openscad/issues/3400> that some folks were looking to use the same functionality to be able to output their CAM G-Code. Was this functionality ever implemented? If so, where/how? If not, are there any objections to me implementing something like this and requesting a PR? EBo --
TP
Torsten Paul
Mon, Feb 10, 2025 11:05 PM

On 10.02.25 23:56, John David via Discuss wrote:

If not, are there any objections to me implementing something like this
and requesting a PR?

For OpenSCAD scripts, the situation has not changed. Those can't
have a write() function.

I still hope we can get the Python support integrated eventually,
that would allow such things without extra work. With no help
moving that topic forward, there's no timeline though.

ciao,
Torsten.

On 10.02.25 23:56, John David via Discuss wrote: > If not, are there any objections to me implementing something like this > and requesting a PR? For OpenSCAD scripts, the situation has not changed. Those can't have a write() function. I still hope we can get the Python support integrated eventually, that would allow such things without extra work. With no help moving that topic forward, there's no timeline though. ciao, Torsten.
JB
Jordan Brown
Tue, Feb 11, 2025 1:44 AM

On 2/10/2025 3:05 PM, Torsten Paul via Discuss wrote:

On 10.02.25 23:56, John David via Discuss wrote:

If not, are there any objections to me implementing something like this
and requesting a PR?

For OpenSCAD scripts, the situation has not changed. Those can't
have a write() function.

To amplify on that a bit... this is a deliberate design decision.  It
should be safe for you to download an OpenSCAD program and run it,
without fear that it will scribble on your files.

On 2/10/2025 3:05 PM, Torsten Paul via Discuss wrote: > On 10.02.25 23:56, John David via Discuss wrote: >> If not, are there any objections to me implementing something like this >> and requesting a PR? > > For OpenSCAD scripts, the situation has not changed. Those can't > have a write() function. To amplify on that a bit... this is a deliberate design decision.  It should be safe for you to download an OpenSCAD program and run it, without fear that it will scribble on your files.
RD
Revar Desmera
Tue, Feb 11, 2025 2:09 AM

On Feb 10, 2025, at 2:56 PM, John David via Discuss discuss@lists.openscad.org wrote:


I want to write some generic text (similar to echo statements) to a user defined output file.  My interest in this is to use it in conjunction with the timing tests to output the results from dozens of tests.  In the past, I have used stuff like this to output the configuration of a simulation, so I know what all the parameters were.

I see in the GitHub issues "Allow OpenSCAD to open and write out text files #3400" https://github.com/openscad/openscad/issues/3400 that some folks were looking to use the same functionality to be able to output their CAM G-Code.

Was this functionality ever implemented?  If so, where/how?

You cannot write to a file with OpenSCAD. At all. This is for safety reasons. Wouldn’t want to have a malicious OpenSCAD script installing malware on your machine. Python in OpenSCAD theoretically could, though.

However, you CAN run OpenSCAD from the command-line and redirect its console text into a file, then post-process it with a script to remove unwanted cruft.

-Revar

> On Feb 10, 2025, at 2:56 PM, John David via Discuss <discuss@lists.openscad.org> wrote: > >  > I want to write some generic text (similar to echo statements) to a user defined output file. My interest in this is to use it in conjunction with the timing tests to output the results from dozens of tests. In the past, I have used stuff like this to output the configuration of a simulation, so I know what all the parameters were. > > I see in the GitHub issues "Allow OpenSCAD to open and write out text files #3400" <https://github.com/openscad/openscad/issues/3400> that some folks were looking to use the same functionality to be able to output their CAM G-Code. > > Was this functionality ever implemented? If so, where/how? You cannot write to a file with OpenSCAD. At all. This is for safety reasons. Wouldn’t want to have a malicious OpenSCAD script installing malware on your machine. Python in OpenSCAD theoretically could, though. However, you CAN run OpenSCAD from the command-line and redirect its console text into a file, then post-process it with a script to remove unwanted cruft. -Revar
JB
Jon Bondy
Tue, Feb 11, 2025 2:10 AM

Wow.  Every other programming language I know of (and I've been writing
code since the late 60s) has been able to write files. Were those
languages considered insecure or dangerous?

How about we allow file writes with a global Setting that defaults to
Cannot Write but the user can change to Allow Writes. That way, everyone
is safe, right until they agree to allow Writes?

I imagine this is not the first time this conversation has occurred, and
I am about to get the Wisdom of the Ages descend upon me...

Jon

On 2/10/2025 8:44 PM, Jordan Brown via Discuss wrote:

On 2/10/2025 3:05 PM, Torsten Paul via Discuss wrote:

On 10.02.25 23:56, John David via Discuss wrote:

If not, are there any objections to me implementing something like this
and requesting a PR?

For OpenSCAD scripts, the situation has not changed. Those can't
have a write() function.

To amplify on that a bit... this is a deliberate design decision. It
should be safe for you to download an OpenSCAD program and run it,
without fear that it will scribble on your files.


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

--
This email has been checked for viruses by AVG antivirus software.
www.avg.com

Wow.  Every other programming language I know of (and I've been writing code since the late 60s) has been able to write files. Were those languages considered insecure or dangerous? How about we allow file writes with a global Setting that defaults to Cannot Write but the user can change to Allow Writes. That way, everyone is safe, right until they agree to allow Writes? I imagine this is not the first time this conversation has occurred, and I am about to get the Wisdom of the Ages descend upon me... Jon On 2/10/2025 8:44 PM, Jordan Brown via Discuss wrote: > On 2/10/2025 3:05 PM, Torsten Paul via Discuss wrote: >> On 10.02.25 23:56, John David via Discuss wrote: >>> If not, are there any objections to me implementing something like this >>> and requesting a PR? >> >> For OpenSCAD scripts, the situation has not changed. Those can't >> have a write() function. > > To amplify on that a bit... this is a deliberate design decision. It > should be safe for you to download an OpenSCAD program and run it, > without fear that it will scribble on your files. > > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org -- This email has been checked for viruses by AVG antivirus software. www.avg.com
JB
Jordan Brown
Tue, Feb 11, 2025 2:24 AM

On 2/10/2025 6:10 PM, Jon Bondy wrote:

Wow.  Every other programming language I know of (and I've been
writing code since the late 60s) has been able to write files. Were
those languages considered insecure or dangerous?

Er... Yes.  Do you run random Python/C/Perl/shell programs that you
download from sites like Thingiverse?

Or:  when you open and print a Word document or an Excel spreadsheet,
can it scribble on your disk?

How about we allow file writes with a global Setting that defaults to
Cannot Write but the user can change to Allow Writes. That way,
everyone is safe, right until they agree to allow Writes?

Plausible.  (Maybe even require confirmation on every open-for-write.)

I imagine this is not the first time this conversation has occurred,
and I am about to get the Wisdom of the Ages descend upon me...

It all depends on how paranoid you are about security issues.  I'm not
the authority so my opinion doesn't really matter, but it's not a can of
worms that I would open.

On 2/10/2025 6:10 PM, Jon Bondy wrote: > Wow.  Every other programming language I know of (and I've been > writing code since the late 60s) has been able to write files. Were > those languages considered insecure or dangerous? Er... Yes.  Do you run random Python/C/Perl/shell programs that you download from sites like Thingiverse? Or:  when you open and print a Word document or an Excel spreadsheet, can it scribble on your disk? > How about we allow file writes with a global Setting that defaults to > Cannot Write but the user can change to Allow Writes. That way, > everyone is safe, right until they agree to allow Writes? Plausible.  (Maybe even require confirmation on every open-for-write.) > I imagine this is not the first time this conversation has occurred, > and I am about to get the Wisdom of the Ages descend upon me... It all depends on how paranoid you are about security issues.  I'm not the authority so my opinion doesn't really matter, but it's not a can of worms that I would open.
LM
Leonard Martin Struttmann
Tue, Feb 11, 2025 2:25 AM

*However, you CAN run OpenSCAD from the command-line and redirect its
console text into a file, then post-process it with a script to remove
unwanted cruft. *

Plus (at least on recent builds), you can right-click in the Console pane,
and save the interactive log to a file and post-process it.  Personally, I
have no problem with OpenSCAD's lack of file writing capabilities.  But,
that is probably because I DO know a little bit of Python and Regular
Expressions, and grep; so post-processing is relatively painless for me.

On Mon, Feb 10, 2025 at 8:11 PM Revar Desmera via Discuss <
discuss@lists.openscad.org> wrote:

On Feb 10, 2025, at 2:56 PM, John David via Discuss <
discuss@lists.openscad.org> wrote:


I want to write some generic text (similar to echo statements) to a user
defined output file.  My interest in this is to use it in conjunction with
the timing tests to output the results from dozens of tests.  In the past,
I have used stuff like this to output the configuration of a simulation, so
I know what all the parameters were.

I see in the GitHub issues "Allow OpenSCAD to open and write out text
files #3400" https://github.com/openscad/openscad/issues/3400 that some
folks were looking to use the same functionality to be able to output their
CAM G-Code.

Was this functionality ever implemented?  If so, where/how?

You cannot write to a file with OpenSCAD. At all. This is for safety
reasons. Wouldn’t want to have a malicious OpenSCAD script installing
malware on your machine. Python in OpenSCAD theoretically could, though.

However, you CAN run OpenSCAD from the command-line and redirect its
console text into a file, then post-process it with a script to remove
unwanted cruft.

-Revar


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

*However, you CAN run OpenSCAD from the command-line and redirect its console text into a file, then post-process it with a script to remove unwanted cruft. * Plus (at least on recent builds), you can right-click in the Console pane, and save the interactive log to a file and post-process it. Personally, I have no problem with OpenSCAD's lack of file writing capabilities. But, that is probably because I DO know a little bit of Python and Regular Expressions, and grep; so post-processing is relatively painless for me. On Mon, Feb 10, 2025 at 8:11 PM Revar Desmera via Discuss < discuss@lists.openscad.org> wrote: > > > On Feb 10, 2025, at 2:56 PM, John David via Discuss < > discuss@lists.openscad.org> wrote: > >  > I want to write some generic text (similar to echo statements) to a user > defined output file. My interest in this is to use it in conjunction with > the timing tests to output the results from dozens of tests. In the past, > I have used stuff like this to output the configuration of a simulation, so > I know what all the parameters were. > > I see in the GitHub issues "Allow OpenSCAD to open and write out text > files #3400" <https://github.com/openscad/openscad/issues/3400> that some > folks were looking to use the same functionality to be able to output their > CAM G-Code. > > Was this functionality ever implemented? If so, where/how? > > > You cannot write to a file with OpenSCAD. At all. This is for safety > reasons. Wouldn’t want to have a malicious OpenSCAD script installing > malware on your machine. Python in OpenSCAD theoretically could, though. > > However, you CAN run OpenSCAD from the command-line and redirect its > console text into a file, then post-process it with a script to remove > unwanted cruft. > > -Revar > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
JJ
jon jonbondy.com
Tue, Feb 11, 2025 2:34 AM

I download programs off of the internet ALL OF THE TIME.  They usually
write to the files that I ask them to write to (Save, Save As).  Even
OpenSCAD itself writes to my hard drive.  I do not avoid OpenSCAD
because it can write to my hard drive.  What is the difference between a
program or an app and a script?

Sure, Word documents should not write to arbitrary places, because I do
not think of them as programs.  But OpenSCAD scripts are programs but do
not get executed unless I cause them to be executed.  The onus is on me
to check or trust.

I like my proposal that writes be allowed in the language, but
preventable by the user.

Of course I like my proposal!  It is mine!

Jon

On 2/10/2025 9:24 PM, Jordan Brown wrote:

On 2/10/2025 6:10 PM, Jon Bondy wrote:

Wow. Every other programming language I know of (and I've been
writing code since the late 60s) has been able to write files. Were
those languages considered insecure or dangerous?

Er... Yes.  Do you run random Python/C/Perl/shell programs that you
download from sites like Thingiverse?

Or:  when you open and print a Word document or an Excel spreadsheet,
can it scribble on your disk?

How about we allow file writes with a global Setting that defaults to
Cannot Write but the user can change to Allow Writes. That way,
everyone is safe, right until they agree to allow Writes?

Plausible.  (Maybe even require confirmation on every open-for-write.)

I imagine this is not the first time this conversation has occurred,
and I am about to get the Wisdom of the Ages descend upon me...

It all depends on how paranoid you are about security issues.  I'm not
the authority so my opinion doesn't really matter, but it's not a can
of worms that I would open.

I download programs off of the internet ALL OF THE TIME.  They usually write to the files that I ask them to write to (Save, Save As).  Even OpenSCAD itself writes to my hard drive.  I do not avoid OpenSCAD because it can write to my hard drive.  What is the difference between a program or an app and a script? Sure, Word documents should not write to arbitrary places, because I do not think of them as programs.  But OpenSCAD scripts are programs but do not get executed unless I cause them to be executed.  The onus is on me to check or trust. I like my proposal that writes be allowed in the language, but preventable by the user. Of course I like my proposal!  It is mine! Jon On 2/10/2025 9:24 PM, Jordan Brown wrote: > On 2/10/2025 6:10 PM, Jon Bondy wrote: >> Wow. Every other programming language I know of (and I've been >> writing code since the late 60s) has been able to write files. Were >> those languages considered insecure or dangerous? > > Er... Yes.  Do you run random Python/C/Perl/shell programs that you > download from sites like Thingiverse? > > Or:  when you open and print a Word document or an Excel spreadsheet, > can it scribble on your disk? > >> How about we allow file writes with a global Setting that defaults to >> Cannot Write but the user can change to Allow Writes. That way, >> everyone is safe, right until they agree to allow Writes? > > Plausible.  (Maybe even require confirmation on every open-for-write.) > >> I imagine this is not the first time this conversation has occurred, >> and I am about to get the Wisdom of the Ages descend upon me... > > It all depends on how paranoid you are about security issues.  I'm not > the authority so my opinion doesn't really matter, but it's not a can > of worms that I would open. >
WF
William F. Adams
Tue, Feb 11, 2025 2:50 AM

On Monday, February 10, 2025 at 05:56:51 PM EST, John David via Discuss discuss@lists.openscad.org wrote:

I want to write some generic text (similar to echo statements) to a user defined output file.  My interest in this is to use it 
in conjunction with the timing tests to output the results from dozens of tests.  In the past, I have used stuff like this to output 
the configuration of a simulation, so I know what all the parameters were.

I see in the GitHub issues "Allow OpenSCAD to open and write out text files #3400" 
https://github.com/openscad/openscad/issues/3400 that some folks were looking to use the same functionality to be able to 
output their CAM G-Code.  

Was this functionality ever implemented?  If so, where/how?

If not, are there any objections to me implementing something like this and requesting a PR?

No, it wasn't implemented, there are sort-of work-arounds.

If you are willing to use PythonSCAD/OpenPythonSCAD:

https://pythonscad.org/

then writing out files works as expected.

I've been working on that at:

https://github.com/WillAdams/gcodepreview

which is pretty much working.

William

On Monday, February 10, 2025 at 05:56:51 PM EST, John David via Discuss <discuss@lists.openscad.org> wrote: >I want to write some generic text (similar to echo statements) to a user defined output file.  My interest in this is to use it  >in conjunction with the timing tests to output the results from dozens of tests.  In the past, I have used stuff like this to output  >the configuration of a simulation, so I know what all the parameters were. > >I see in the GitHub issues "Allow OpenSCAD to open and write out text files #3400"  ><https://github.com/openscad/openscad/issues/3400> that some folks were looking to use the same functionality to be able to  >output their CAM G-Code.   > >Was this functionality ever implemented?  If so, where/how? > >If not, are there any objections to me implementing something like this and requesting a PR? No, it wasn't implemented, there are sort-of work-arounds. If you are willing to use PythonSCAD/OpenPythonSCAD: https://pythonscad.org/ then writing out files works as expected. I've been working on that at: https://github.com/WillAdams/gcodepreview which is pretty much working. William
JB
Jordan Brown
Tue, Feb 11, 2025 3:00 AM

The question is whether the 5th percentile OpenSCAD user, who is running
it to get to the Customizer, understands that an OpenSCAD program could
scribble on their disk.  (Or even what it would mean for it to scribble
on their disk.)  These are precisely the people who should never
download programs except from app stores, because they have no idea how
to vet the trustworthiness of the supplier.

There are any number of stories of social engineering people to click
through warnings.

The only thing that would save us from a CNN minute would be that there
are very few OpenSCAD users, and so it's a small target (so villains
won't bother) and the sample size for gullibility is small (and so even
if the villains bother, they won't get very many one-in-a-thousand victims).

The question is whether the 5th percentile OpenSCAD user, who is running it to get to the Customizer, understands that an OpenSCAD program could scribble on their disk.  (Or even what it would mean for it to scribble on their disk.)  These are precisely the people who should never download programs except from app stores, because they have no idea how to vet the trustworthiness of the supplier. There are any number of stories of social engineering people to click through warnings. The only thing that would save us from a CNN minute would be that there are very few OpenSCAD users, and so it's a small target (so villains won't bother) and the sample size for gullibility is small (and so even if the villains bother, they won't get very many one-in-a-thousand victims).