I try working with *.bat and *exe file in window from Julia level.
Is file vol.bat with:
cmd
vol
inside.
I am trying get value of number HD to some julia variable
julia> myc=`vol.bat`
`vol.bat`
julia> x=run(myc)
C:\Users\PC\AppData\Local\Julia-0.7.0>cmd
Microsoft Windows [Wersja 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. Wszelkie prawa zastrzeżone.
C:\Users\PC\AppData\Local\Julia-0.7.0>vol
Wolumin w stacji C nie ma etykiety.
Numer seryjny woluminu: 0EA8-3B46
Process(`vol.bat`, ProcessExited(0))
C:\Users\PC\AppData\Local\Julia-0.7.0>exit
julia> x
Process(`vol.bat`, ProcessExited(0))
How to do it ? I expect somthink like:
x==" Wolumin w stacji C nie ma etykiety.
Numer seryjny woluminu: 0EA8-3B46"
Propably is simplest way …
Paul
1 Like
shell> cat vol.bat
vol
julia> myc = `vol.bat`
`vol.bat`
julia> x = read(myc, String)
"\r\nC:\\Users\\Kristoffer>vol\r\n Volume in drive C has no label.\r\n Volume Serial Number is 2458-0EE6\r\n"
julia> print(x)
C:\Users\Kristoffer>vol
Volume in drive C has no label.
Volume Serial Number is 2458-0EE6
maybe
1 Like
Yes, yes yes,
Thanks
if
t="\r\nC:\\Users\\Kristoffer>vol\r\n Volume in drive C has no label.\r\n Volume Serial Number is 2458-0EE6\r\n"
julia> Meta.parse(t)
ERROR: Base.Meta.ParseError("\"\\\" is not a unary operator")
Stacktrace:
[1] #parse#1(::Bool, ::Bool, ::Bool, ::Function, ::String, ::Int64) at .\meta.jl:129
[2] #parse at .\none:0 [inlined]
[3] #parse#4(::Bool, ::Bool, ::Function, ::String) at .\meta.jl:164
[4] parse(::String) at .\meta.jl:164
[5] top-level scope at none:0
That’s not Julia code, so calling Meta.parse
on it fails with a parse error.
You can use split()
for example to parse the text. I assume you searched for “parse” and found that Meta.parse
, which as Stefan already told not what you want.
Here are some examples:
julia> t = "\r\nC:\\Users\\Kristoffer>vol\r\n Volume in drive C has no label.\r\n Volume Serial Number is 2458-0EE6\r\n"
"\r\nC:\\Users\\Kristoffer>vol\r\n Volume in drive C has no label.\r\n Volume Serial Number is 2458-0EE6\r\n"
julia> split(t, "\r\n")
5-element Array{SubString{String},1}:
""
"C:\\Users\\Kristoffer>vol"
" Volume in drive C has no label."
" Volume Serial Number is 2458-0EE6"
""
julia> split(t)[end]
"2458-0EE6"
Or regular expressions using match
:
julia> match(r"Serial Number is (.*)\r\n", t)[1]
"2458-0EE6"
1 Like