I have created a project folder TESTEXE and built an executable as below:
module testexe
Base.@ccallable function julia_main()::Cint
try
testApp()
catch
Base.invokelatest(Base.display_error, Base.catch_stack())
return 1
end
return 0
end
function testApp()
filehandle = open("$(@__DIR__)/input.txt", "w")
write(filehandle, "Hello world!")
close(filehandle)
end
end # module
1- When I click on the executable it creates a txt file input.txt in the folder of the source file ./src/input.txt . Can the txt file be generated in the same folder of executable? so then I only need the generated folder to use it in another machine.
2- The project folder is located in the directory C:\ . When I moved it to desktop C:\Users\amroa\OneDrive\Desktop\testexe , running the executable don’t generate the txt file in the folder of the source file. What should I do to handle this issue to make the executable works on different folders and machines?
Only trying to answer your first question. I tested your MWE with the following instrumentation:
function testApp()
println("$(@__DIR__)/input.txt")
filehandle = open("$(@__DIR__)/input.txt", "w")
write(filehandle, "Hello world!")
close(filehandle)
end
and it seems @__DIR__ references the source directory of your application. If you change the open call to
filehandle = open("input.txt", "w")
the file will be created in your current working directory. I then tried to get the command line parameters via ARGS with
Base.@ccallable function julia_main()::Cint
println("$ARGS")
try
testApp()
catch
Base.invokelatest(Base.display_error, Base.catch_stack())
return 1
end
return 0
end
yielding
String[]
So it seems to me your best bet is to use file system functions, especially cd to dynamically manipulate your working directory.
P.S.: working with ‘PackageCompiler’ is rather time consuming. Building this simple example lasts between 2 minutes (incremental) to 5 minutes (full) on my machine…
Do you run your executable from Windows explorer? I’d recommend to use Windows command prompt, because then you’ll be able to inspect the stdout and stderr output of your program