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

more process features #307

Closed
StefanKarpinski opened this issue Dec 13, 2011 · 10 comments
Closed

more process features #307

StefanKarpinski opened this issue Dec 13, 2011 · 10 comments
Assignees
Milestone

Comments

@StefanKarpinski
Copy link
Member

Things that are needed:

  • writing to file handles: run(echo Hello | fh)
  • reading from file handles: run(fh | sort -nr)
  • writing to files by name: run(echo Hello > "hello.txt")
  • append to files by name: run(echo world >> "hello.txt")
  • reading from files by name: run("/usr/share/dict/words" > tr A-Z a-z)
  • programmatically writing to a pipeline
  • better name than spawn for starting a process without blocking
  • make run(cmd) throw an error on failure
  • use success(cmd) to just test for success or failure
@ghost ghost assigned StefanKarpinski Dec 13, 2011
@JeffBezanson
Copy link
Member

I think I'd rather have run return the exit code than have to put a try-catch block around it almost every time.

@StefanKarpinski
Copy link
Member Author

See a9fd119: if you want the success status, use the success function instead. I really think this is the right way to go. I've been bitten by sloppy perl/ruby scripts that swallow failing commands silently far too often. We do not want to repeat that design mistake.

@StefanKarpinski
Copy link
Member Author

Silently swallowing command failure, brittle string interpolation into command strings, and unnecessarily using the shell to spawn external pipelines are my three bugaboos with doing shell-like scripting from ruby and perl. With this, we've eliminated all three.

@JeffBezanson
Copy link
Member

Also noting that we need a more abstract interface for fdio(read_from(cmd).fd, true).

@StefanKarpinski
Copy link
Member Author

Yes, definitely.

@nolta
Copy link
Member

nolta commented Apr 28, 2012

  • boolean operators: run(test -d $dir&&echo $dir)

Edit: nevermind, i should just write success(test -d $dir) && run(echo $dir)

@StefanKarpinski
Copy link
Member Author

Yep. The former can't actually work because && and || are control flow constructs, not operators.

@Keno
Copy link
Member

Keno commented Jan 9, 2013

This all works now:

julia> using Base.FS

julia> readall("test.julia")
could not open file test.julia
 in open at io.jl:277
 in open at io.jl:297
 in readall at io.jl:424

julia> open("test.julia",JL_O_WRONLY|JL_O_CREAT,0o644)
File("test.julia",true,11)

julia> fh=ans
File("test.julia",true,11)

julia> run(`echo Hello`>fh)
true

julia> close(fh)
File("test.julia",false,-1)

julia> run(`echo World`>>"test.julia")
true

julia> run("test.julia">`tee`)
Hello
World
true

julia> pipe=write_to(`tee`>STDOUT)[1]
NamedPipe(connected,0 bytes waiting)

julia> write(pipe,"Test\n")
no method write(NamedPipe,ASCIIString)

julia> print(pipe,"Test\n")

Test
julia> run(`doesnotexist`)
execvp(): No such file or directory
failed process: Process(`doesnotexist`, ProcessExited(-1)) [-1]
 in pipeline_error at process.jl:385
 in run at process.jl:374

julia> success(`false`)
false

julia> success(`true`)
true

julia> success(`echo DONT PRINT THIS`)
true

@aviks
Copy link
Member

aviks commented Jan 9, 2013

Are the open() functions in base/io.jl now deprecated?

@Keno
Copy link
Member

Keno commented Jan 9, 2013

No, but they will be soon (i.e. as soon as I'm done writing the new one). We're moving to an all-libuv stack for I/O. The great thing about the module system is that i can just develop this one without ever touching the old one and when it's ready write import Base.open, etc., delete io.jl and be done with it.

StefanKarpinski pushed a commit that referenced this issue Feb 8, 2018
Fix Compat on master by updating walkdir
Keno pushed a commit that referenced this issue Oct 9, 2023
…#307)

* Replace the slow slotname Dict with a counter ("age")-based mechanism

Co-authored-by: "Kristoffer Carlsson" <[email protected]>

* make assignment_counter an Int64 to prevent overflow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants