0

I have the following script:

$ cat mathtest.m
pardir=DirectoryName @ $InputFileName;
Print["test parent dir: ", pardir]

If I run it like this, I get:

$ wolfram -script mathtest.m
test parent dir: /home/me/

If I run it like this, I get:

$ wolframscript -file mathtest.m
test parent dir: 

Could somebody explain me this weird behavior? Apart from this I haven't noted any differences between running scripts in both methods. However, I do need the second one to give me the correct path.

I am on Wolfram Language 11.1.1 Engine for Linux x86 (64-bit).

Santiago
  • 1,201
  • 8
  • 16
  • What does it return for: Print["test parent dir: ", {$InputFileName, NotebookFileName[]}]? – Kuba Aug 23 '17 at 11:58
  • 1
    @Kuba NotebookFileName[] should only work with a front end, no ... ? Here it's command line only. The behaviour is weird indeed, and I don't like it, but there is a technical explanation for it (in the 'duplicate' answer I linked) – Szabolcs Aug 23 '17 at 12:09
  • 1
    @Szabolcs yep, though many things that should be are not and I got used to trying ridiculous things. – Kuba Aug 23 '17 at 12:13
  • thanks @Szabolcs, indeed that 'duplicate' answer explains in a very weird way the behavior. I hope I am safe by changing all my -file to -script calls. @Kuba, yes I also tried NotebookFileName[] and indeed I get the error FrontEndObject::notavail. – Santiago Aug 23 '17 at 12:18
  • You may be able to get the information from $ScriptCommandLine instead. – Szabolcs Aug 23 '17 at 12:24

0 Answers0