I created a bash script to randomize some number, then send it to > /dev/ttyUSB0. This is a converter (USB to serial, RS-232) that is plugged through the notebook USB.
Right now, my only wish is to see these random numbers (sent from one terminal) on some other terminal (same PC). I've already tried using screen, cat, minicom, and other internet-favorites, but with no success.
Right now, when I run the random-number script (while other terminal is trying to read the output from the port), the "best" answer is saying that the ttyUSB0 is unavailable at the moment.
Appreciate your help,
Regards;
#!/bin/bash
while true;
do
number=$RANDOM
echo $number >/dev/ttyUSB0
echo $number
sleep 4
done
I expected to see the random numbers through other terminal. Instead, I'm reading different kind of errors.
I could do it quite simply with minicom now. After resetting parameters, I reconfigured minicom (minicom -s). After starting the minicom (to /dev/ttyUSB0) in one terminal, I ran my script in another terminal (that echos random numbers to /dev/ttyUSB0) and could finally receive all data.
Related
Right so I wanted to automate a process which I have to do quite often for a program that I run quite often and sometimes open up multiple of.
Normally I open up Terminal and type in the following commands in order:
cd ExoClient
mono ExoClient.exe
(email)
(pass)
So I made an executable file for this called login.command on my mac.
I typed in this is order:
cd ExoClient
mono ExoClient.exe
example_email#gmail.com
example_password
So the first two lines work but the last two don't do anything. I thought that this could be because the top 2 commands are actual mac commands and the last two lines are just inputs. But I don't know how to make sure the inputs are inputted.
OR another reason why it might not work could be because I need to delay the inputs. I'd love to know what I can input here to make it wait a second before an input is inputted.
Thanks for reading, would appreciate any help.
I made a similar post on mac rumours.
The solution was to do :
cd ExoClient
mono ExoClient.exe email pass
The first thing to understand about the command-line is that there's a bunch of different things in play.
The first is the commands themselves, these are typically typed in or run from a script.
The second is "standard input" or STDIN, which is where programs take keyboard input. As far as you're concerned there's no difference when using the shell, but to the shell itself there's a huge difference. That program wants input from STDIN. The shell script is being told to run two subsequent commands.
Instead try this:
cd ExoClient
echo "example_email#gmail.com\
example_password" | mono ExoClient.exe
The | character means "send output to" in rough terms, so the output of echo goes through to the mono program. Output, or STDOUT, is another thing the shell wants to deal with.
Or have a secondary file that contains those two lines and give that as "input":
cd ExoClient
mono ExoClient.exe < login.txt
Where login.txt has the two lines and < means "take input from this file".
I have a Matlab program that runs different unix commands fairly often. For this question let's assume that what I'm doing is:
unix('ls test')
It happens to me quite frequently that I accidentally press a key(like enter or the arrow keys) f.e. when I'm waking up my display from standby. In theory this shouldn't interfere with the unix command. Though unfortunately, Matlab will take this input and forward it right into the execution of the command. The above command then becomes something like this:
unix('ls te^[0Ast')
(Side note: ^[0A is the hex representation of the linefeed character)
Obviously, this will produce an error.
Does anyone have an idea how to work around this issue?
I was thinking that there might be a way to start Matlab with my script in a way that doesn't forward any user input from within the unix shell.
#!/bin/bash
matlab -nodisplay -nosplash -r "runMyScript();"
Can I somehow pipe the user-input somewhere else and isolate Matlab from any sort of input?
That is not very specific question, but let me try. I can see several options. I am assuming that matlab is text terminal application.
There is nohup(1) command. Since you use linux, chances are that there is non-posix version if it which says in it's man page: If standard input is a terminal, redirect it from /dev/null.
$ nohup matlab -nodisplay -nosplash -r "runMyScript();"
You can redirect /dev/null yourself
$ matlab -nodisplay -nosplash -r "runMyScript();" < /dev/null
But matlab can actually re-open it's stdin ignoring what you piped into it (for example ssh does that, you can't use echo password | ssh somewhere.
if you are running in graphics environment you may want to minimise the window, so that it does not receive any input. Probably not your case, you would figure out yourself :)
you may try to wake up by hitting "Ctrl", similar key or mouse
You may run matlab in screen(1) command disconnect from the screen or switch to different window. Screen is a program allowing you to create virtual terminals (similar to virtual desktops in GUI). If you haven't heard of screen, I suggest you to look at some tutorials. Googling for gnu screen tutorial seems to offer quite a few.
I'm starting a windows-program with wine in a shell script. Now I would like to pass keystrokes and texts to it. I've tried xvkbd as mentioned in this question, but the program just outputs the letter/text into the terminal and exits after that. Here's an example:
`wine BERCon.exe > output.txt &`
sleep 5;
`xvkbd -text "N"`
Is that even possible to do? I checked the man-page of xvkbd to check if I can change the focus somehow, but it seems like thats not possible.I noticed that if I do something like echo "N" | wine BERCon.exe the N actually gets passed to wine and wine puts it into the program, but gets into a loop after that and continues to input that letter.
I want to write a program that can be run as a backgrounded task (i.e. my-thing &), and that will beautifully provide relevant output when necessary.
However, with background tasks that print to the terminal, there's always this annoying little progression:
bash-3.2$ my-thing &▏
bash-3.2$ my-thing &
bash-3.2$ -- Hello from my-thing!
-- now let me start doing what I do best ...
▏
… notice that we now have no prompt before the cursor, not to mention that there's an ugly erraneous prompt where my program spat out output while a prompt had already been printed.
Thus, I want three things, only one of which I don't have any idea how to go about doing:
Detect whether my program is being run in the background, and alter my output/operation accordingly (i.e. print out less useless information; queue further information to only be output when the program is foregrounded again; etceteras)
Clear out the prompt (if it already exists) when suddenly printing information to a terminal we've been backgrounded in
Inform the terminal after I've finished whatever I'm printing to the terminal for, somehow forcing it to re-draw a new prompt below the content I've added
The third is the only one I have absolutely no idea how to go about; though I've got some inklings on the other two, any links or suggestions there would be appreciated as well.
Equally appreciated, even, would be links to any programs (any language/environment) which already have modes that operate this; as I could attempt to reverse-engineer/spelunk their implementation.
This works for me:
echo 'sleep 1; echo; echo hi' > /tmp/hi
chmod +x /tmp/hi
zsh
/tmp/hi &
asdfsadf # type whatever, here.
After the 'hi' gets echo'd, zsh knows to redraw your prompt with the 'asdfasdf' intact.
So, no big surprise: zsh being better than bash.
I have some long running scripts with breaks requiring input/interaction to continue but when I switch to another window I'd like to be notified (by sound) that a task is complete and now awaiting input.
I would prefer to be able to play an audio clip (*.mp3, *.ogg, etc.) but wouldn't care if the only solution is to make the PC Speaker beep noise.
Any ideas? I'm open to any CLI utilities I can install that play sounds that in turn I can execute when needed.
FYI: My System is running WinXP Pro.
UPDATE: Doh! My Windows > Control Panel > Sounds > Default Beep: was set to (none). Grrr...
Problem solved.
This will make a beep from within bash
echo -en "\007"
Try this:
echo ^G
(^G is obtained by ctrl+G).
Note: you can't copy and paste this code in a batch file, it won't work. To obtain a ^G character in a file, type in a cmd window:
echo ^G > beep.txt
(again, ^G is obtained by ctrl+G).
Then you'll have a file named beep.txt, open it with notepad, there will be a square character. This is our ^G once it is saved in a file.
You can then copy and paste it in a batch file to make a sound (don't forget to put "echo" in front of it).
spd-say
sleep 2; spd-say 'get back to work'
Infinite loop with -w if you need extra motivation:
sleep 2; while true; do spd-say -w 'get back to work'; done
or if you prefer the carrot:
sleep 2; while true; do spd-say -t female1 -w "I'm done, come back to me, darling"; done
Pre-installed on Ubuntu 14.04 via the package speech-dispatcher: http://releases.ubuntu.com/trusty/ubuntu-14.04.4-desktop-amd64.manifest for blind people I suppose?
See also: https://askubuntu.com/questions/277215/how-to-make-a-sound-once-a-process-is-complete
Also add a popup
This combo is a life saver, b stands for beep:
b() ( spd-say 'done'; zenity --info --text "$(date);$(pwd)" & )
and then:
super-slow-command;b
If I'm somewhere in the room, I'll hear it and know that the long job is done.
Otherwise, I'll see the popup when I get back to my computer.
Related:
How to show a GUI message box from a bash script in linux?
https://superuser.com/questions/345447/how-can-i-trigger-a-notification-when-a-job-process-ends
https://askubuntu.com/questions/409611/desktop-notification-when-long-running-commands-complete
Listen to your cooler
I'm joking of course, but for compilation I noticed that I use often use this queue subconsciously. When the cooler stops humming for a while, it means that the compilation is over!
I know your question was for Window but just putting this here for any Mac OSX users who come across this article. OSX 10+ comes with the say command:
say "I'm done"
For example:
sleep 5 && say "I'm done waiting 5 seconds"
By setting this variable as follows
PROMPT_COMMAND="echo -en '\a'"
then bash will beep every time it shows the prompt. When you do not need it anymore,
unset PROMPT_COMMAND
To play the system sound from Windows command line you can run:
rundll32 user32.dll,MessageBeep
It should work on all version of Windows.
copy con beep.bat [Enter]
#echo off [Enter]
echo [Ctrl+G] [Enter]
[Ctrl+Z] [Enter]
beep.bat [Enter]
Simple answer without ^G
echo -en "\007"
In my bash profile I've added a BEEP to the script using #GregReynolds solution above then added this to PS1:
GREEN="\[\033[0;32m\]"
BEEP=$(echo -en "\007")
export PS1="$GREEN : ${BEEP}"
source ~/.bash_profile - you should hear the beep after the command prompt returns
I have git-autocomplete on usually so I've provided a much simplified version above