Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When giving - as the program, read code from standard in. #43191

Merged
merged 1 commit into from
Jan 12, 2022

Conversation

fredrikekre
Copy link
Member

I couldn't figure out another way of passing args while reading from stdin. This seems to be what python does (for example):

$ julia - foo bar <<EOF
println(ARGS)
EOF
["foo", "bar"]

$ python - foo bar <<EOF
import sys; print(sys.argv)
EOF
['-', 'foo', 'bar']

It is perhaps a bit strange that this takes another code path compared to

julia <<EOF
...
EOF

since that ends up all the way in here:

if isa(input, File) || isa(input, IOStream)
but not sure it matters much.

@fredrikekre fredrikekre changed the title When giving - as the program, read program from standard in. When giving - as the program, read code from standard in. Nov 22, 2021
@StefanKarpinski StefanKarpinski added the minor change Marginal behavior change acceptable for a minor release label Nov 22, 2021
@Keno
Copy link
Member

Keno commented Nov 23, 2021

julia <<EOF
...
EOF

Shouldn't we just make this work? If we're already autoswitching based on stream type detection, why not at least make it useful.

@fredrikekre
Copy link
Member Author

Shouldn't we just make this work?

It does work, just ends up taking a different path than what I implemented here.

@fredrikekre
Copy link
Member Author

Bump.

@vtjnash vtjnash merged commit 98e2321 into master Jan 12, 2022
@vtjnash vtjnash deleted the fe/stdin-program branch January 12, 2022 00:13
@maleadt
Copy link
Member

maleadt commented Jan 12, 2022

I guess this can now be changed to passing -?

julia/base/loading.jl

Lines 1406 to 1413 in 2ed3ec4

io = open(pipeline(`$(julia_cmd()::Cmd) -O0
--output-ji $output --output-incremental=yes
--startup-file=no --history-file=no --warn-overwrite=yes
--color=$(have_color === nothing ? "auto" : have_color ? "yes" : "no")
$trace
--eval 'eval(Meta.parse(read(stdin,String)))'`, stderr = internal_stderr, stdout = internal_stdout),
"w", stdout)
# write data over stdin to avoid the (unlikely) case of exceeding max command line size

@vtjnash
Copy link
Member

vtjnash commented Jan 12, 2022

True, that would seem to be identical now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor change Marginal behavior change acceptable for a minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants