1

I want to get the current working directory, or the directory/path where the script being called when using wolframscript. Without frontend, i.e. not using NotebookDirectory.

Because when I want to get the current directory by NotebookDirectory in wolframscript, it shows:

FrontEndObject::notavail: A front end is not available; certain operations require a front end.

Updated

With the help of @Edmund, I use Directory to solve this problem.

But it introduced another problem. If I use Directory in package files, the notebook cannot use the package, because Directory returns home path. But if I use NotebookDirectory, the wolframscript cannot use the package, because NotebookDirectory uses frontend. How can I solve this?

Updated

With the help of @MB1965 If[$InputFileName="", NotebookDirectory[], Directory[]] will solve the above problem.

Further, If I use

ppNoteBookDir = If[$BatchInput, Directory[], NotebookDirectory[]];
Needs["msgCommon`", FileNameJoin[{ppNoteBookDir, "msg_common.wl"}]]

Then the first time I evaluate the notebook, it shows: enter image description here

It need evaluate the notebook a second time to work right. Why and how to fix it? Thanks.

cmal
  • 191
  • 1
  • 7

0 Answers0