Comments (12)
I am having the same issue here as @patchthecode. The bash command does not seem to ever return.
I can get it to unzip with this command:
run(bash: "unzip ./myfile.zip"
If I then put a flag in the command it no longer returns:
run(bash: "unzip -a ./myfile.zip"
or
run(bash: "unzip ./myfile.zip -d ./myfile2
Interestingly those same commands work fine when I use runAndPrint instead:
try! runAndPrint(bash: "unzip -a ./myfile.zip"
try! runAndPrint(bash: "unzip ./myfile.zip -d ./myfile2"
I am just trying to avoid the console output because its very verbose and doesn't add anything to my script.
from swiftshell.
Ok. i tried just unzipping a small text file. Same thing.
Investigating further..
from swiftshell.
OK. So i have now tried the runAndPrint
command
and it correctly unzips the file on terminal, but,
it is sad because i cannot get the output like below
let output = try SwiftShell.runAndPrint("unzip", "/Users/jt/Desktop/Bob/myZipFile.zip", "-d", "/Users/jt/Desktop/Bob")
from swiftshell.
runAndPrint
doesn't return anything, so that is expected. Could you try
let output = try SwiftShell.run("unzip", "/Users/jt/Desktop/Bob/myZipFile.zip", "-d", "/Users/jt/Desktop/Bob")
to see if it is bash that never returns. If that doesn't work I'll take a look when I get back to my computer on Monday.
from swiftshell.
ok. I'll update this over the weekend. And give you the results.
from swiftshell.
I have tested this with runAndPrint
using SwiftShell 3.0.1 and it is working fine unless unzip
asks for input (if e.g. the files I am unzipping already exist in the destination) and I run it from the terminal. Then the application never finishes. If I run it in Xcode and provide the input in its console it's working fine. It doesn't matter if I build the executable with Xcode or with the Swift Package Manager.
This is very strange, I don't really have any theories at the moment. Have you found any way to work around it?
from swiftshell.
@kareman the workaround for now is to use runAndPrint
Unfortunately, i cannot get a return value because runAndPrint
was not built for that.
Although the run
command it fails, note that it works with other terminal commands.. it just hangs when unzippng.
I remember way back in my school days something about flushing stdout buffers? But im not sure if this has anything to do with this. It was too long ago.
from swiftshell.
I think the problem only occurs when the “unzip” command asks for an answer to a question (like if it should overwrite already existing files). And it seems it only does this when standard input is a terminal. Some workarounds are
let output = run(bash: "null | unzip /User/myName/Desktop/myZipFile.zip -d /User/myName/Desktop/")
or
let output = "".run("unzip", "/Users/jt/Desktop/Bob/myZipFile.zip", "-d", "/Users/jt/Desktop/Bob")
Or maybe you can call the unzip command with the flags "-n never overwrite existing files" or "-o overwrite files WITHOUT prompting".
Please let me know if any of these suggestions solve your problem.
from swiftshell.
What happens if you try let output = "".run(bash: "unzip -a ./myfile.zip")
?
from swiftshell.
Yea you are correct it only happens when unzip asks for more input. I thought I was careful to make sure to delete the unzipped file after I was done with it. On a second run of the same script it fails. I was missing a delete of a __MACOSX directory that unzip creates. That was causing unzip to ask for input.
let output = "".run(bash: "unzip -a ./myfile.zip")
Clears the prompt and allows it to continue.
from swiftshell.
Excellent. I'll close this issue now.
@patchthecode feel free to reopen it if your problem was not resolved.
from swiftshell.
@kareman i'll try it today and let you know
from swiftshell.
Related Issues (20)
- runAsync(bash"") cannot write nothing on onStringOutput on mac osx app standalone HOT 2
- `waitUntilExit` cause slow execution HOT 1
- How to execute rm -rf /xxx/* HOT 3
- Could not find module 'SwiftShell' for target 'arm64-apple-macos'; found: x86_64, x86_64-apple-macos
- How to execute an ncurses-based command? HOT 2
- run shell empty output HOT 4
- PID of the command launched using SwiftShell
- The interactive command is suspended at the terminal
- Im trying to find a way to make a run cancellable
- Not support `Pod` command HOT 5
- New syntax? HOT 2
- Xcode 12 beta / Swift 5.3 not building HOT 5
- Tupling issue? HOT 1
- Request for an API that do not exit when executable to run is not found HOT 2
- Final released Swift 5.3 crashes on compile HOT 10
- Using ubuntu-latest for GHAction Test HOT 4
- Make run and throwable HOT 1
- onStringOutput returning nothing.
- Allow `run` to take an array HOT 1
- How to pipe with different contexts?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swiftshell.