terminal

How can I run a terminal command in my swift menu bar app?

北战南征 提交于 2019-12-12 10:17:33
问题 I have made a menu bar app and I want this command to be run on press rm -rf ~/.Trash/* The code I currently have is this: @IBAction func toggleClicked(sender: NSMenuItem) { let task = NSTask() task.launchPath = "/bin/sh" task.arguments = ["rm", "-rf", "~/.Trash/*"] task.launch() task.waitUntilExit() } But when I run this, I get the following error: /bin/rm: /bin/rm: cannot execute binary file I dont really understand why I'm getting this error since I can open terminal and run /bin/sh, then

What error do you find in this code/program? Erro is it wont run unless you type a number in first

删除回忆录丶 提交于 2019-12-12 10:01:25
问题 So my question is on this: This program is supposed to calculate the area of circle the user inputs a number comes out with the answer also any invalid input is not allowed i use the try-catch but it wont work... Thank you so much for you time everyone :)) Here is the code: import java.util.Scanner; import java.io; /** * * @author Osugule */ public class AreaCircle { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here

How to exit if statement in bash without exiting program?

送分小仙女□ 提交于 2019-12-12 09:20:03
问题 Rewriting this question to avoid more downvotes, since it's too late for me to delete it: I'm writing a script that asks a user for confirmation and before sourcing some other scripts. To simplify the code, imagine that there are two scripts which might be sourced , but I want the user to either source none or exactly one of the scripts - not both. I was trying to use a statement of the form if true source-script else exit which wasn't working because I'd exit the if statement, but also the

Executing shell command on Android

╄→гoц情女王★ 提交于 2019-12-12 09:16:54
问题 I'm wondering if Cordova or any plugin for Cordova enables me to execute a command in the android shell? Similar to doing adb shell myCoolBinary -doThisStuff on a desktop machine connected to the phone. Googling for this only returns tutorials for how to use the Cordova cli desktop application, which absolutely NOT what I'm looking for. I want to execute commands ON the phone. 回答1: I ended up writing my own plugin. I mostly put it together from another question that was about doing root shell

Calling a function in a PHP script from the command line

早过忘川 提交于 2019-12-12 08:54:57
问题 I have a script that has a bunch of different parameterized functions. Is it possible to call any of these functions from the command line and pass in the arguments instead of me having to hard code the function calls in the script? F.Y.I: I do know how to execute a simple PHP script from the command line doesn't quite call the function, remember script.php has around 5 different functions and I am looking to call only 1, is that possible 回答1: No, you cannot do that directly. You have a few

Posting array using cURL in Terminal

你。 提交于 2019-12-12 08:53:40
问题 I'm trying to build a webservice for an app, so the data stores in an online database I have. I'm currently building the php document, and I'm curious as to how I can POST an array using cURL in the Terminal Mac app . You see, the application will send an array consisting of strings to the webservice. For example something like this ["String 1", "String 2", "String 3"] . But to test if the code I have for inserting these values into the database works, I need to pass this data to the

Using octave headless

风流意气都作罢 提交于 2019-12-12 08:39:58
问题 Is there a possibility to use Octave headless. Something like this octave < "5+4" >result.txt 回答1: Using octave --silent --eval 5+4 > result.txt you'll get ans = 9 in result.txt . See octave --help for details about command-line arguments. Yet, there is this infamous ans = that might be remove using sed , e.g. octave --silent --eval 'x=5+4; y=x+1; disp(y)' | sed -e 's/ans = //' >> result.txt which add the appropriate result ( 10 ) in result.txt . It should not be too hard to wrap this into a

Allow JavaScript from Apple Events in Safari through Terminal Mac

放肆的年华 提交于 2019-12-12 08:25:00
问题 I'm writing a program that executes do javascript in Safari. The only problem is that I'm trying to make the app give its self permission to do it. I'm trying to locate the file that handles the Safari developer preferences so that I can do this. Does anyone have any idea where this might be or how to change these settings? 回答1: It's in Safari's preferences plist at ~/Library/Preferences/com.apple.Safari.plist . The key you want is AllowJavaScriptFromAppleEvents . You can set it using

use conditional in bash script to check string argument

大城市里の小女人 提交于 2019-12-12 07:41:27
问题 I am trying to write my shell script thing.sh so that upon making it an executable and running it with the single letter ``A" like so: $ ./thing.sh A I get the output A If argument 1 is not A, I want the output Not A Here is my code so far : #!/bin/bash if [ "$1" -eq "A"] then echo "A" else echo "Not A" fi which returns, no matter what I enter, ./thing.sh: line 3: [:missing `]' Not A I am trying what I hoped would check something with one or several letters and compare it against the letter A

Redirect System.in to swing component

只谈情不闲聊 提交于 2019-12-12 07:23:57
问题 Hey guys I am making a terminal application using Swing and Apache Commons. I was able to redirect System.out and System.err to a JTextArea easily but how do I do that for System.in ? Will I need to override Inputstream methods? Do I need to convert the String from JTextArea to byte array and then pass it to InputStream ? Code examples would be nice. 回答1: I recently tried the same thing, here's my code: class TexfFieldStreamer extends InputStream implements ActionListener { private JTextField