Click here to Skip to main content
15,885,153 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Forbidden File Names? Pin
kmoorevs3-Jan-23 4:59
kmoorevs3-Jan-23 4:59 
GeneralRe: Forbidden File Names? Pin
Paul Sanders (the other one)3-Jan-23 3:44
Paul Sanders (the other one)3-Jan-23 3:44 
GeneralRe: Forbidden File Names? Pin
obermd3-Jan-23 3:56
obermd3-Jan-23 3:56 
GeneralRe: Forbidden File Names? Pin
kmoorevs3-Jan-23 5:03
kmoorevs3-Jan-23 5:03 
GeneralRe: Forbidden File Names? Pin
Dave Kreskowiak3-Jan-23 6:41
mveDave Kreskowiak3-Jan-23 6:41 
GeneralRe: Forbidden File Names? Pin
Gee.3-Jan-23 9:34
Gee.3-Jan-23 9:34 
GeneralRe: Forbidden File Names? Pin
kmoorevs3-Jan-23 9:52
kmoorevs3-Jan-23 9:52 
GeneralRe: Forbidden File Names? Pin
trønderen3-Jan-23 19:35
trønderen3-Jan-23 19:35 
Changing CWD can be a pain in the neck (or maybe even lower down).

Even seasoned programmers may believe that they change CWD, complaining that it fails. That is because the way they do it causes a new process to be spun off, and the CWD applies to that process. When it terminates, "Task completed", the changed WD dies with that process. Make sure that the process executing the CWD is not a child process. If you call some API with a CWD parameter, it might start a new process and use the parameter to set the CWD for that process, without affecting the CWD of the calling process.

You have the same situation with the PATH value: A child process cannot modify the path of its ancestor process. It could change the user profile to change the initial PATH for shells started at a later time, but the shell reads the user profile at startup, and is not affected by profile updates while it is running. The same goes for arbitrarily named environment variables.

Most build systems structure a build in a series of job steps, usually with each job step run as a separate process. Countless developers have tried to modify the environment (CWD, PATH or other environment variables) in one job step, expecting the modification to apply to later steps. It fails, even if the the first step updates the user profile. True enough: The next job step process is started after the profile update, but it is (in several build systems, maybe all) a plain child process, not a shell, so it inherits the environment of the build system process that creates it. The user profile is read by the shell when initializing, not at a plain process creation.

In my last job, we had a large crowd of very qualified system developers. Yet, I had to explain again and again why their CWD, PATH and environment updates "failed". I urged them to forget about inheriting the environment by child processes, and rather transfer such values through the Registry, but two thirds of the SW development group were Linux developers by heart, having been forced to accept working under Windows to get a job, bluntly refusing to use any Windows mechanism unknown in Linux if there was any way to avoid it. As long as they could bitch at lengths about the worthless environment handling in Windows, not realizing that a Linux build system would behave in exactly the same way.

So: When you think that you have set the WD of a given process, check it out to be 100% sure: After modifying it, retrieve the CWD to a variable you can inspect in a debugger, or print it out e.g. on the error device.
GeneralRe: Forbidden File Names? Pin
kmoorevs3-Jan-23 9:46
kmoorevs3-Jan-23 9:46 
GeneralRe: Forbidden File Names? Pin
trønderen3-Jan-23 19:47
trønderen3-Jan-23 19:47 
GeneralRe: Forbidden File Names? Pin
ormonds4-Jan-23 15:18
ormonds4-Jan-23 15:18 
GeneralRe: Forbidden File Names? Pin
englebart15-Jan-23 10:00
professionalenglebart15-Jan-23 10:00 
GeneralRe: Forbidden File Names? Pin
kmoorevs16-Jan-23 7:24
kmoorevs16-Jan-23 7:24 
GeneralRe: Forbidden File Names? Pin
LM Hess29-Jan-23 7:27
LM Hess29-Jan-23 7:27 
GeneralClassic FORTRAN Pin
trønderen30-Dec-22 5:28
trønderen30-Dec-22 5:28 
GeneralRe: Classic FORTRAN Pin
Graeme_Grant30-Dec-22 6:32
mvaGraeme_Grant30-Dec-22 6:32 
GeneralRe: Classic FORTRAN Pin
Craig Robbins30-Dec-22 7:21
Craig Robbins30-Dec-22 7:21 
GeneralRe: Classic FORTRAN Pin
Slacker00730-Dec-22 7:36
professionalSlacker00730-Dec-22 7:36 
GeneralRe: Classic FORTRAN Pin
trønderen30-Dec-22 9:18
trønderen30-Dec-22 9:18 
GeneralRe: Classic FORTRAN Pin
haughtonomous2-Jan-23 21:56
haughtonomous2-Jan-23 21:56 
GeneralRe: Classic FORTRAN Pin
lewist573-Jan-23 8:43
lewist573-Jan-23 8:43 
GeneralRe: Classic FORTRAN Pin
trønderen3-Jan-23 9:21
trønderen3-Jan-23 9:21 
GeneralRe: Classic FORTRAN Pin
lewist573-Jan-23 9:49
lewist573-Jan-23 9:49 
GeneralRe: Classic FORTRAN Pin
jsc423-Jan-23 10:53
professionaljsc423-Jan-23 10:53 
GeneralRe: Classic FORTRAN Pin
Peter_in_27803-Jan-23 11:07
professionalPeter_in_27803-Jan-23 11:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.