I'm trying to render a file using a utility template in a Mason template (using an ancient CMS Bricolage). That may not be important.
The $m->scomp should end up with a nicely composed json file which I then manually create, print to and close:
my $article_body = $m->scomp('/util/render_apple_story.mc');
open my $fh, '>', $articlerootjson;
print {$fh} $article_body . "\n";
close $fh;
Then I try to execute a process that detects that file (with Python) and sends it to Apple
$output = `PYTHONIOENCODING=UTF-8 /var/home/tyee/PyAppleAPI/create_article.py https://news-api.apple.com $channel $key $secret $articleroot`;
print "return is $output \n";
But each FIRST time i execute the template, it fails to create the file.
And yet it runs the command in the backticks, which returns that there is no json file.
So somehow the perl program is continuing to step through either while the $m->scomp or file open/close commands are still in motion, and then exiting before the file can even be created.
The SECOND time through, if I rerender the template(re-run the perl) the file will be created.
What gives? Is there some way of running the backtick portion ONLY if the $m->scomp and file open + close have completed ?
Turns out the directory structure up to where the story uri was didn't yet exist. I tried all kinds of forced previewing of output channels to no avail.
So after looking at shortcuts to create entire directory structures to a path, I had to do the inelegant:
And then it let me open the file. Opening the file with error reporting would have helped me I somehow did not think that was the step that was failing so I overlooked it.