Giter VIP home page Giter VIP logo

Comments (12)

Nordeast avatar Nordeast commented on May 28, 2024 1

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.

patchthecode avatar patchthecode commented on May 28, 2024

Ok. i tried just unzipping a small text file. Same thing.
Investigating further..

from swiftshell.

patchthecode avatar patchthecode commented on May 28, 2024

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.

kareman avatar kareman commented on May 28, 2024

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.

patchthecode avatar patchthecode commented on May 28, 2024

ok. I'll update this over the weekend. And give you the results.

from swiftshell.

kareman avatar kareman commented on May 28, 2024

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.

patchthecode avatar patchthecode commented on May 28, 2024

@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.

kareman avatar kareman commented on May 28, 2024

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.

kareman avatar kareman commented on May 28, 2024

What happens if you try let output = "".run(bash: "unzip -a ./myfile.zip")?

from swiftshell.

Nordeast avatar Nordeast commented on May 28, 2024

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.

kareman avatar kareman commented on May 28, 2024

Excellent. I'll close this issue now.

@patchthecode feel free to reopen it if your problem was not resolved.

from swiftshell.

patchthecode avatar patchthecode commented on May 28, 2024

@kareman i'll try it today and let you know

from swiftshell.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.