I am trying to prompt the user of my .jl file to enter user entered multiple destinations.
Basically I need the user to give an input & an output. I know in java you would use a scanner, or accept arguments when it is compiled in the command line. I am fine with either option. From what I have found looking through the Julia Documentation I think I could accomplish the first way of assigning a variable to the readline function.
(String)in = (String)Readline(STDIN)
From my understanding the variable 'in' should now contain a String of the user's input. I am encountering an error, in that when I compile my .jl code, because my command prompt does not stop to read user input, and just finishes reading the .jl code.
The first item to note in the code in your question is:
Julia 1.0.0 now uses
stdin
instead ofSTDIN
.Next, the
(String)
typecasting is not something you need or want to do in Julia.Thus your code could read (though we get an error):
So variable
in
is in conflict with a JuliaBase.in
variable. Just use a another variable name.This code is now working, but it has no prompt. Your answer provides an example input function with a prompt which you defined like this:
The
chomp
function removes a single trailing\n
newline character from the input string. Docs here.Example use of the function here:
Command Line Args Method
As the docs point out, to just print out the arguments given to a script, you can do something like this:
Here is an example of above code running on the Windows command line:
You can also print out the script file name as shown, PrintArgs.jl.
After searching & testing I found one solution and decided to reply to it here. I had to declare my own function to be able to get the program to accept user input.
I am not sure what the chomp function does, but I know it works for what I was asking. I am still curious if you can do something in Julia similar to java and C String args[], in which you pass extra information while you are telling your command to run. Something like the following.