Ant secureInputHandler: requires user to press enter before accepting input - ant

I use SecureInputHandler to accept passwords from the end user in ant script, but it forces user to press Enter before it allows text input.
Is this expected behavior? Also, I didn't find much documentation on this topic, please feel free to point me to any resources on this.
<input message="Please enter password:" addproperty="password.property">
<handler classname="org.apache.tools.ant.input.SecureInputHandler" />
</input>

SecureInputHandler requires Ant 1.7.1 or greater (to support the handler) and Java 6 or greater (to provide the Console class).
If you don't have the right Ant version, you'll get an error. If you don't have the right Java version, Ant falls back to the default input handler.
Note that you can also use:
<handler type="secure"/>
The javadoc and source can be seen here.
Using Ant 1.8.2 and Java 1.6 in a windows cmd shell, I get this:
test:
Please enter password:<cursor here>
The password is masked. You type the password and hit Enter.
Using a Cygwin shell, or Java 1.5 in cmd shell, I get this:
test:
[input] Please enter password:
<cursor here>
The password is not masked. You type the password and hit Enter.
Using Eclipse console, I couldn't get the password to enter at all. I type, it is echoed on the console, I press Enter, nothing happens.
I notice that in the documentation of the Input task, it says:
IDE behaviour depends upon the IDE: some hang waiting for input, some
let you type it in. For this situation, place the password in a
(secured) property file and load in before the input task.
In other words, it may not work in an IDE, use a work around.

exec was interfering with the input tasks.
It can be solved by specifying inputstring=”” in the exec task.
See exec causes other tasks to hang or leads to strange behaviour of <input> tasks in the Ant FAQ.

Related

Command Palette shortcut not working in Sublime Text3

I am using Sublime Text 3 and am trying to access the command palette using ctrl-shift-P. This shortcut is not working. I am running Ubuntu 16.04. Any help to fix this would be greatly appreciated.
The two main reasons for this sort of situation (regardless of the key sequence in question) are:
A user installed plugin or custom key binding is bound to the same key, which is taking precedence and stopping the action that you expect from happening
Some external process is eating the keystroke before Sublime even gets to see it.
In order to diagnose which it might be, you can open the Sublime console with View > Show Console or by pressing Ctrl+`, then enter the following commands:
sublime.log_commands(True)
sublime.log_input(True)
Once you've done that, press the key sequence in question and check the output in the console. In your specific case, you should see this:
key evt: shift+control+p
command: show_overlay {"overlay": "command_palette"}
Not seeing the command that you expect indicates that some other action is bound to the key in question, and usually the command will lead you to what's causing the problem.
Not seeing the key event means that some external process is eating the key. This could be some global program or it could be something in the OS doing it (in the case of Linux, the window manager).
It's also possible that you see a different key event entirely, which indicates that your keyboard layout is not what Sublime expects.
Depending on the situation you may be able to disable whatever is eating the key. Presuming you can't find what that is or otherwise don't want to disable it, or if the event shows that Sublime is seeing a different key, the solution is to change the key binding.
The procedure for this is to find the binding that's not working and copy it to your custom key bindings, changing the key as appropriate to something that Sublime can see.
For core Sublime key bindings, look in Preferences > Key Bindings to find the key in question. For packages, that's generally in Preferences > Package Settings > PACKAGENAME > Key Bindings.
In your case, the setting is a default key binding, so looking in the default key bindings yields the following binding, which you can put in your custom key bindings and change as needed:
{
"keys": ["ctrl+shift+p"],
"command": "show_overlay",
"args": {"overlay": "command_palette"}
},
Something that I found:
Weirdly my Sublime Text 3 doesn't recognise the command if I use LCTRL abd LSHIFT. Using RCTRL+RSHIFT+p opens the command palette, so try that.
In my case it was an app called https://noiz.io which had stolen this shortcut. It can take a bit of time as there isn't (AFAIK) a way to find the application which is bound to a shortcut.
In my case a Pomodoro app I just installed had a command for starting clock defined with the same shortcut and it was stealing the event from Sublime. Just removed the shortcut assignment and it works now.

How to eliminate leading [java] label from Ant's <java> task output?

I'm invoking the <java> task using Ant to run a program that prints out some stuff to stdout that ultimately, I'd like the user to be able to copy-paste easily. However, each line of stdout is prefixed with [java], which makes things needlessly challenging for the user.
Is there some way to print just the output of System.out.println(...) without getting prefixed with [java]?
Set ANT_ARGS=-emacs, see ant FAQ:
Ant adds a "banner" with the name of the current task in front of all
logging messages - and there are no built-in regular expressions in
your editor that would account for this.
You can disable this banner by invoking Ant with the -emacs switch.
[...]
Also ant manual Running Apache Ant listing all cli options might be helpful :
-emacs, -e produce logging information without adornments

How to read a user input in a text filed in ruby on rails and pass the value to a shell script command

I am very new to ruby on rails and I have a very simple question.
I am able to read the user input from a text field in ruby on rails
#user = params[:user]
I have to pass this value as an argument to a shell script
I tried a number of things, but nothing works
run_command "./file.sh #{#user}"
and
%x(./file.sh #{#user})
The script receives "{user="
Any help is appreciated!
First, make sure you escape any parameters you pass to command line. You may be easily attacked via command line injection this way. Try this instead:
system "/path/to/file.sh #{#user.shellescape}"
You may also want to try exec, depending on how you want to track output. Please see http://ruby-doc.org/core-2.3.0/Kernel.html for more details on both

Ant exec task: How can I read input from console stdin?

I have a call to Ant exec task that needs to accept input from console stdin. Unfortunately, I cannot find a way to do this. The stdin filehandle seems closed to console input at runtime.
It is possible to specify input using attributes input and inputstring. However, I need to prompt for user input at the console.
How can I do this?
From the documentation of the task:
Note that you cannot interact with the
forked program, the only way to send
input to it is via the input and
inputstring attributes. Also note that
since Ant 1.6, any attempt to read
input in the forked program will
receive an EOF (-1). This is a change
from Ant 1.5, where such an attempt
would block.
You could try to use the input-task to prompt for input in the ant-buildfile and pass these input with the inputstring-attribute of exec. I can't think of a better option at the moment.

Ant output to 2 different sources?

I'm running Ant with output fed to a log file:
ant -logfile file.txt target-name
I'd also like to print some simple progress information to the console though. The answer seems to be a BuildEvent listener that writes to the console every time a new target is hit, but the documentation explicitly states:
A listener must not access System.out and System.err directly since ouput on these streams is redirected by Ant's core to the build event system.
Did I miss something? Is there a way to do this?
Ant replaces the System.out & System.err streams to remap messages printed there through it's own logging system.
That said, you can still get access to the ACTUAL OS streams by using java.io.FileDescriptor#out
Actually, the answer is Log4jListener.
There is a sample log4j configuration for logging into both console and file shown in the above link. You can then use an <echo> task with an appropriate level parameter to selectively decide what gets printed to console.
Thanks for the answers! I'm slow, but this is still something that I'd like to get right.
I've managed to get something working more or less like I want using carej's suggested approach with the java.io.FileDescriptor#out stream and an Ant scriptdef like this:
<scriptdef name="progress-text" language="javascript" >
output = new java.io.PrintStream(new java.io.FileOutputStream(java.io.FileDescriptor.err))
output.println(self.text)
</scriptdef>
Now I'm just left wondering how wize is this approach? Is there inherit risk in using the underlying OS streams directly?
EDIT:
2 Points which might be useful to anyone else with a similar question:
This article has a very good description of the Ant I/O system: http://codefeed.com/blog/?p=68
java.lang.System does something very similar to set System.out and System.err in the first place.
All of this gave me a little more confidence in this approach.

Resources