I'm currently coding in Julia, and at some point, I have to run a .exe program at the Command Prompt. Let's name that program "x.exe". I decided to add the following line to my code for Julia to execute the program inside of the code:
run(pipeline('x.exe input.txt 5 500',stdout="output.txt"))
The code works perfectly, but I have to insert manually the values "5" and "500", which are respectively, the number of rows in the input.txt file and the number of items of each row in the input.txt file. They also are the number of rows and columns of an Array stored in Julia.
Is there a way for the code to read those numbers directly? I tried
writedlm("size.txt", transpose([size(Array)[1],size(Array)[2]])," ")
and then
run(pipeline('x.exe input.txt type size.txt',stdout="output.txt"))
but it don't work....
You can use @sprintf
, e.g. as follows:
julia> using Printf
julia> x = [[1,2,3], [4,5,6]]
2-element Array{Array{Int64,1},1}:
[1, 2, 3]
[4, 5, 6]
julia> a = @sprintf("%d", size(x)[1][1])
"2"
julia> b = @sprintf("%d", size(x[1])[1][1])
"3"
julia> run(pipeline(`x.exe input.txt $a $b`,stdout="output.txt"))
As you can see, Julia uses the same method to interpolate variables into commands as the shell does (see the Julia manual section on Running External Programs).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With