I have a main directory with subdirectories numbered (1, 2, 3, ...). In each folder there is an exe file. I execute this code:

ParallelDo[RunProcess[NotebookDirectory[] <> ToString[i] <> "\\main.exe", ProcessDirectory -> NotebookDirectory[] <> ToString[i]], {i, 1, 10}]

And I get a bunch of errors: "A front end is not available; certain operations require a front end." and of course, the error mentioning that $Failed is not a string. I stripped the problem down to this: RunProcess is allright, what is problem is that ParallelDo can't process NotebookDirectory[]:

ParallelDo[Print[NotebookDirectory[] <> ToString[i] <> "\\main.exe"], {i, 1, 10}]

(same errors)

What is the problem? How can I solve this?

  • 1
    $\begingroup$ The subkernels do not have a front end connected, so they do not know what is the NotebookDirectory[]. Assign the notebook directory to a variable and use that in ParallelDo. $\endgroup$ – Szabolcs Mar 31 '17 at 23:31
  • $\begingroup$ Oh! That works and the solution is so trivial...Thank you! $\endgroup$ – user16320 Mar 31 '17 at 23:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.