Writing to mplayer's stdin from bash script.

I was just fulling with some bash script in order to automate the listening of my favorite radio stations via mplayer and a bash script. Going through the mplayers manual I saw the option -slave.
-slave
This option switches on slave mode. This is intended for use of MPlayer as a backend to other programs. Instead of intercepting keyboard events, MPlayer will read simplistic command lines from its stdin. The section SLAVE MODE PROTOCOL explains the syntax.
At first I thought "ok, easy". I made some tries like "mplayer -slave -quiet .... < /tmp/stdin &" and then something like "echo -e 'mute' > /tmp/stdin" but it wouldn't work.
Is it possible to send a process to the background inside a bash script and then write to it's stdin?
SLAVE MODE PROTOCOL
If the -slave option is given, playback is controlled by a line-based protocol. Each line must contain one command otherwise one of the following tokens:
Commands
seek <value> [type=<0/:1/:2>]
Seek to some place in the movie. Type 0 is a relative seek of +/:- <value> seconds. Type 1 seek to <value> % in the movie. Type 2 is a seek to an absolute position of <value> seconds.
audio_delay <value>
Adjust the audio delay of value seconds
quit
Quit MPlayer
pause
Pause/:unpause the playback
grap_frames
Somebody know ?
pt_step <value> [force=<value>]
Go to next/:previous entry in the playtree.
pt_up_step <value> [force=<value>]
Like pt_step but it jumps to next/:previous in the parent list.
alt_src_step <value>
When more than one source is available it selects the next/:previous one (only supported by asx playlist).
sub_delay <value> [abs=<value>]
Adjust the subtitles delay of +/:- <value> seconds or set it to <value> seconds when abs is non zero.
osd [level=<value>]
Toggle osd mode or set it to level when level > 0.
volume <dir>
Increase/:decrease volume
[contrast|brightness|hue|saturation] <-100-100> [abs=<value>]
Set/:Adjust video parameters.
frame_drop [type=<value>]
Toggle/:Set frame dropping mode.
sub_visibility
Toggle subtitle visibility.
sub_pos <value>
Adjust subtitles position.
vo_fullscreen
Switch to fullscreen mode.
tv_step_channel <dir>
Select next/:previous tv channel.
tv_step_norm
Change TV norm.
tv_step_chanlist
Change channel list.
gui_[loadsubtitle|about|play|stop]

FIFO's are awesome and can be (ab)used for a lot of cool stuff.
I've written some applications that do just what you are trying to do ( http://github.com/trapd00r/rmcd and http://github.com/trapd00r/RPD ), if you need inspiration.
As for the backgrounding - you want to make a 'daemon', to detach from the running shell. See man fork, man 3 setsid and man 3 wait / man 3 waitpid (or my daemonize() function).

Similar Messages

  • How to send 2 variable value from bash script into java.class

    #!/bin/bash
      a=10
      b=20
       echo $a $b | java addition
    donehi there,
    currently i have a simple java coding ( a + b ). and i m trying to connect with bash script but this bash script coudln't Enter 2nd value (b=20) while i running for it. may i know how do i can Enter 2 value into it?
    output from terminal
    [seng@localhost java_class]$ bash addition.sh
    =======================================================================
    simulation 1
    Num_a       = 10
    Num_b       = 20
    Enter your Num_a : 10
    Enter your Num_b : Exception in thread "main" java.lang.NumberFormatException
       at java.lang.Integer.parseInt(java.lang.String, int, boolean) (/usr/lib/libgcj.so.6.0.0)
       at java.lang.Integer.parseInt(java.lang.String) (/usr/lib/libgcj.so.6.0.0)
       at filter_god.GOD(java.util.List, java.util.List, java.lang.String, java.lang.String, int) (Unknown Source)
       at filter_god.main(java.lang.String[]) (Unknown Source)
       at gnu.java.lang.MainThread.call_main() (/usr/lib/libgcj.so.6.0.0)
       at gnu.java.lang.MainThread.run() (/usr/lib/libgcj.so.6.0.0)
    =======================================================================

    That code will send both numbers on a single line in standard input to the java process. So if the process reads standard input, it will get a single line that has this in it: "10 20".
    I'm guessing you're sending that whole line to Integer.parseInt. But a valid number doesn't have a space in the middle.
    You should split up the line using String.split. Or use a StringTokenizer. Or a regular expression. Or you can use a java.util.Scanner. Or a java.io.StreamTokenizer. Or maybe some other stuff that has slipped my mind at the moment.

  • Using admin_client.jar from bash script

    Hello,
    When I make a call "java -jar admin_client.jar" from a bash script I always get 0 for $? even when there are errors reported in the console. How can I check the status correctly?
    S

    Greetings,
    Can you see the console when running the script? I would try to test something simple like -testDatabaseConnection and you should see a result. If you cannot login the the server directly, pipe the output to a file. Next, build up your bash script with additional complexity as you go. Post the results here for the group to analyze.
    THX
    -Michael
    Edited by: Michael F. Hardy on Dec 2, 2008 2:02 PM

  • Find gives permission denied on files when executed from bash script.

    I've written a really basic script just to check what new music was added to my library over the past n days:
    #!/bin/bash
    echo "Check for days?"
    read days
    `find /home/tom/Music/ -iname "*.*" -type f -mtime -$days -print`
    If I run the find from the shell it runs fine but the script always gives this error:
    ./listNewMusic.sh: line 7: /home/MrGone/Music/Smod/SModcast-19.mp3: Permission denied
    Anyone know why?
    Thanks.

    It is because you're running the find command in a sub-shell.  What is returned by the sub-shell is being run by your script.
    Change:
    `find /home/tom/Music/ -iname "*.*" -type f -mtime -$days -print`
    to
    find /home/tom/Music/ -iname "*.*" -type f -mtime -$days -print
    Last edited by steve___ (2010-07-10 12:50:38)

  • How do I restart X from the console or from bash script?

    I have searched with google, but can't find any answers not involving gdm or xdm. I need this because I'm writing a simple script that compiles and installs dwm and then restarts x.
    Thanks.

    Ashren wrote:
    lilsirecho, no it does nothing.
    buttons, sudo kill 'pidof X' && startx did work with xdm enabled (I still had to login again, though). The reason I don't use respawn is that I don't like display managers. Is there any way to circumvent them and still have the respawn feature? I want to restart dwm without typing in anything, besides the name of my script.
    Thanks..
    Absolutely.
    Relevant parts of /etc/inittab:
    id:5:initdefault:
    x:5:respawn:/bin/su buttons -l -c "/bin/bash --login -c startx >/dev/null 2>/home/buttons/.xsession-errors"
    "buttons" is of course my login name, and I prefer to have my errors go to a logfile in my home directory, which many display managers do by default.  Or at least GDM.

  • [SOLVED] How to open default text editor from bash script?

    as header states i would like my script to open the desktops default text editor. I use xfce.
    I currently have it set to open medit, however i want to be able to use script on other desktops
    Last edited by orphius (2013-07-12 07:24:34)

    Trilby wrote:
    EDITOR will often not be the default desktop environment editor - it is usually limited to being a systemwide (and usually console-ready) editor.
    xdg-open, or a related tool, can give you the desktop's text editor.
    Truth. VISUAL is typically used for the graphical text editor.
    So, to use VISUAL if it exists, but otherwise default to medit, do:
    editor="${VISUAL:-medit}"
    $editor foo.txt
    Last edited by jakobcreutzfeldt (2013-07-11 07:09:02)

  • Sending email using bash script

    Hello:
    I am working on writing a bash script to notify one or more users by email of certain events. Run from the Terminal command line, and having the script "echo" text of (what would be) a form letter with in-line variable expansion (i.e., ${VARIABLE}), all seems to work as anticipated. Eventually, I want cron to launch this shell script, and send an email to an "on-subnet" user (I have postfix enabled on my Mac, and there are multiple local user accounts).
    I found some stuff on the web about sending mail from bash scripts, and so I made a small little test script, that reads like this:
    #!/bin/bash
    VARIABLE[1]="The 12,345 quick brown foxes "
    VARIABLE[2]="jumped over the 67,890 lazy dogs."
    mail -s "a test email" jv << EOF
    This is a test:
    ${VARIABLE[1]}
    ${VARIABLE[2]}
    This is the last line of the test message.
    EOF
    echo "script completed"
    It worked... almost... It sent a local email to my postfix mail account that read like this:
    This is a test:
    The 12,345 quick brown foxes
    jumped over the 67,890 lazy dogs.
    This is the last line of the test message.
    EOF
    echo "script completed"
    So, I have two questions. First, the easy one (I hope):
    How do I delimit the end of the text, that I want to be the message body of the email, from portions of the script that follow said email text?
    Next question is a little more involved. You know how, in Mail.app, if you go to Mail Preferences>Accounts>Account Information, you can put multiple email addresses, comma-delimited, in the "Email Address" field? So, if a person entered "[email protected], [email protected], [email protected]" in this field, then, even though (s)he may be at home, and using their home ISP's mail server, (s)he could send an email apparently from either their home, work, or school email address. Of course, the mail headers clearly would show it came from and through their home machine and home ISP, but it would be displayed in the recipient's Mail client viewer as having come from one of [email protected], [email protected], or [email protected].
    I'd like to do something similar here, whereby the email (that is being sent to one or more local users' postfix account on my computer) would apparently be sent from "watchdog@localhost" rather than from "jv@localhost" like it seems to do by default. Whatever account the script is run from (or presumbably, whose cron tab is launching the script) is what the "From" address is set to.
    I'd rather not create an additional mail account, because I am using Mac OS X built-in accounts for the postfix mailboxes (I don't want to have to maintain a plaintext username:password file in postfix, and I don't want to create an additional user account on the computer).
    So, is there a way to specify an alternate "From" username when invoking the mail -s ${SUBJECT} ${RECIPIENT} command in a bash script? Or is there a different, alternate mail command that will let me do so? (please include a description of syntax and how I'd package the above message text for the alternate method).
    Thanks in advance, all!

    Hi j.v.,
    The > after EOF is just a typo (or may be added by the Discussion ?) and you must delete it; other > are prompts from the interactive shell. Andy's post shows an interactive use of shell, not a shell script (note the shell prompt % in front of the commands). A typical use of here document may look like
    command <<ENDOFDATA
    ENDOFDATA
    There must be no spaces before and after ENDOFDATA. The word ENDOFDATA can be EOF or any other string which is guaranteed not to appear in the text (the .... in the example above).
    You can modify the From: header by using sendmail command (postfix has it as a compatibility interface):
    /usr/sbin/sendmail -t <<EndOfMessage
    Subject: test mail
    To: jv
    From: watchdog
    This is a test:
    ${VARIABLE[1]}
    ${VARIABLE[2]}
    This is the last line of the test message.
    EndOfMessage
    There must be a blank line between the headers and the mail body.
    I assume that you send these mails only to users on your local Mac. Please do not send mails to remote users by using the sendmail command unless you know what you are doing completely.
    PowerMac G4   Mac OS X (10.4.5)  

  • How to run gdb from a bash script?

    I'm trying to use gdb for the 1st time.  I'd like to start it up by launching a bash script which will provide a file name for gbd commands and a file name for the executeable.  I've tried every which way but nothing works.  Can someone help?

    With respect to .gdbinit, the following is from the gdb.pdf documentation
    <http://www.gnu.org/software/gdb/documentation/>
    When you start gdb, it automatically executes commands from its init files, normally called ‘.gdbinit’. During startup, gdb does the following:
    1. Reads the init file (if any) in your home directory.
    2. Processes command line options and operands.
    3. Reads the init file (if any) in the current working directory.
    4. Reads command files specified by the ‘-x’ option.
    So you can have a different .gdbinit in the current working directory, which can be different for each program you are writing, assuming you wish to use separate directories for your projects.
    gdb has a 'source filename' command, which you can use to execute commands stored in a file anytime you want.  So you could put your breakpoints in a file that you then exeucte within gdb using
    source file.with.your.breakpoints
    Of course the file could have ANY gdb commands in it, not just breakpoints.
    Did you mean you compile your program with -g as in
    gcc -g program.c -o program
    Or did you mean -ggdb I've always used -g, but reading the gcc man page, I do not see any problems using -ggdb.
    Message was edited by: BobHarris

  • HOW DO I  RUN A UNIX BASH SCRIPT FROM JAVA??

    HI. Here's a tricky little problem i have. There's a unix bash script that has some commands in it, that manipulate a file. It appends a certain string variable to a file called users. The users file is an ordinary text file.
    I know this script to work perfectly, when i invoke it like this directyl from the command line: ./addusers.sh
    or even: bash /downloads/selinux/policy/addusers.sh
    Now, i have a java program, and its meant to just execute that script. It doesnt throw any Exceptions at runtime. But when i look at the users file, and expect it to have an extra line that was the string variable, the file is UNTOUCHED!
    Again, direct command line invocation works, but not from java. Here's what my invocation from java looks like:
    Process p = Runtime.getRunTime().exec("bash downloads/selinux/policy/addusers.sh");
    The strange thing is, i tried a different bash command. I tried:
    Process p = Runtime.getRunTime().exec("mkdir /temporary");
    and this worked!
    so why not the other one??
    I cant figure it out.

    You say:
    bash /downloads/selinux/policy/addusers.sh
    And you say in Java:
    Process p = Runtime.getRunTime().exec("bash
    downloads/selinux/policy/addusers.sh");
    As if a leading / would be missing from the Java
    version...nyix says:>
    ...OK sorry about that. i DO have a / in front of the downloads.... section in the java method. So its:
    Process p = Runtime.getRunTime().
    exec("bash /downloads/selinux/policy/addusers.sh");
    HELP please?

  • Bash script to dumpstream many files simultaneously with mplayer

    hi guys
    i have a problem which i´m sure can be solved with the power of bash scripting
    unfortunately i´m no bash scripting guru and all my experiments failed so far
    the problem:
    i have a file in which are links(streaminglinks)
    mplayer offers the funtion to dump such a stream with simply issuing
    mplayer -dumpstream mms://path/to/video -dumpfile video1
    for example.
    now i want mplayer to download this streams specified in the links-file automatically.
    basically all it required is a bash script which goes through the link file and generates a command like mplay -dumpstream <link> -dumpfile video<n>
    (where n is the nth link) and execute it.maybe there a even simpler solutions
    well since i´m not that experienced with bashscripting i can´t solve that problem at my self....
    i´m grateful for any help

    hey guys
    thx for the two scripts.
    my approach was nearly the same as your´s kraluz with the difference that it doesn´t work
    but they both have a little blemish
    they download the files sequentially not simultaneously
    how could that be realised
    thx in advance

  • Running Bash scripts from jsf

    Hey I was just wondering if anyone knows how to run a bash script (whatever.sh) from a jsf page.?? I have a whatever.sh on a tomcat server where my web ap is and I was trying just to run it? Any idea???

    Why do you want to do this operation in a JSF page?
    It is better to do it in a Java class and then call the class from the JSF/ JSP page - keep JSF/ JSP only for disply / view purposes.
    Searc on Google for "How to call unix shell script using Java" for answers.

  • Download Bash script running from Task-bar folder

    Hi, Not sure why but when Im trying to open my Downloads file from the task bar its openning up on my desktop as "Downloads-Bash script! how do i stop this please. Its the same if I open from Finder.
    Thank you all in anticipation of a resolve.

    Enter the following command in a Terminal window by copying or dragging (don’t type):
    xattr -c ~/Downloads
    Press return. You can then quit Terminal. Try the action again. If the same thing happens, relaunch the Finder by selecting
     ▹ Force Quit ▹ Finder
    and pressing return or clicking Relaunch.

  • Executing Bash scripts from Apex

    Hi,
    I have several bash scripts that I would like to execute via APEX (the parameters will be supplied through Text fields, and the "execute" button will execute the script.
    The script will be located in the local server (the server where the APEX is installed), and it will perform several activities - for instance, it will execute EMCLI commands (Grid control command line).
    How can one do it ?
    Regards,
    Roni.

    Hello,
    1. Can you please show me examples of HOW to connect between the existing Scheduled job (I've created a job via dbms_scheduler) and executing it in APEX ?
    2. In addition - I need to complicate things a little bit.
    My job executes a procedure that have arguments.
    The arguments are being generated from several field items that I'll create inside apex.
    (Each variable should be inserted to a dbms_scheduler.set_job_argument_value procedure).
    I'm having trouble to pass the variables - how do I set value to a variables, that I can use in Other pages ?
    Only when I set default values to the items, I could take the default value to other pages.
    I tried to reference them with the format :P2_var_name. (with the dot) or with &P2_var_name.
    Thanks,
    Roni.

  • Why does do shell work differntly from running the same bash script in terminal?

    i have the following a/s:
    set scriptPath to quoted form of ((POSIX path of (path to me)) & lnThumb)       set ftn to ""       repeat            try                 do shell script scriptPath & " " & ppath & " " & ftn                 exit repeat            on error error_message number error_number                  if error_number is not -128 then                      set ftn to (choose file with prompt "select folder thumbnail" default location dir without invisibles)                      set ftn to quoted form of the POSIX path of ftn                 end if            end try       end repeat
    calling this bash script:
    #!/bin/bash -f   cd "$1"  rm ./folderthumb.jpg   if [ $# -gt 1 ]  then      ft=${2/#"$1"\//}  else      ft=$(awk '/folderIcon=/{printf("%s",$1)}' meta.properties  | sed s/folderIcon=// )      if [ 0$ft -eq 0 ]       then          exit 1      fi      ft="thumbs/"$ft  fi  ln -s $ft ./folderthumb.jpg  exit 0
    which works as expected when run from the cli:
    tomw> /Applications/imageProc/fixJAlbum.app/Contents/Resources/Scripts/lnThumb.sh `pwd` `pwd`/thumbs/P1040161.JPG   tomw> ls -l folderthumb.jpg lrwxr-xr-x  1 tomw  admin  19 Oct 22 10:36 folderthumb.jpg -> thumbs/P1040161.JPG
    but fails to strip the common directory when called from do shell:
    tomw> ls -l folderthumb.jpg   lrwxr-xr-x  1 tomw  admin  89 Oct 22 10:36 folderthumb.jpg -> /Users/tomw/Desktop/trip2albequerque/albequerque/oldRailyards2nobHill/thumbs/P1 040133.JPG
    w-t-f???

    Click on the "Use Advanced editor" on the upper Right of the edit box.
    Select the text you want preserved
    Click on the >> icon then select "Syntax Highlighting" -> "Plain"
    And you will get this
       kind of
    output    when    you     post

  • Bash script to pseudo multithread a encode job lame

    Conceptually, I don't see why a bash script couldn't run x simultaneous lame mp3 encodes where x is the number of cores the user selects.  I just don't know how to go about doing it.  Would it make sense to read in all the .wav files to an array, then divide the array into x sub arrays and feed the work out or is there a more simplistic method?
    EDIT: I found this blog entry but I don't fully understand it. 
    Here is my adaptation of his code:
    #!/bin/bash
    # the number of cores you have on your system
    cores=4
    encode() {
    for file; do
    fileout=$(echo "$file" | sed s'/.wav//')
    lame -V 2 "$file" "$fileout".mp3; done
    export -f encode
    find . -name '*.wav' -print0 | xargs -0 -n 1 -P $cores bash -c 'encode "$@"' --
    Can someone explain to me what the last bit does: 'encode"$@"' --
    Last edited by graysky (2010-03-01 22:17:13)

    The last bit calls the encoide function, passing in all the arguments as past to it on stdin.
    'encode "$@"' calls encode and passes it its arguments (as passed to it from the find command).
    -- tells xargs that there are no more command line options, and to interpret anything "-" as part of the file names.
    man find and man xargs for more info.
    The "--" I'm not sure which man page it'll be in but I think it's a GNU thing?

Maybe you are looking for

  • Database Authenticaton

    Hi all, I got the concept of external table authentication in OBIEE but what is the use of database authentication?Is that use for identify the database ?

  • Domained laptop - slow logon when connected to non-domain network

    Hi, I'm looking for ideas on how to solve or workaround this issue, so any help would be appreciated.  Please note that this doesn't appear to be the usual type of "slow login" problem - in fact I'm pretty certain the issue is caused by public DNS se

  • I am not able to fetch data from r3

    Hi all, we have schduled process chain for transaction data and master data.when check the process chain status is green. but when not a single record is coming for any of the process chain.when i check the step by step analysis. gray RFC to source s

  • Urgent: dateformat and culture

    Post Author: bozz CA Forum: .NET Hi I have created a windows service that open a report, set a Dataset as datasource andsend an email with the pdf export attached.The date format in the report is based on the server date format (and not on the thread

  • Memory issue using BO XI Enterprise SDK and ISecurityInfo

    Hello everybody I have a big issue using the XIR2 SDK when I want to get rights for an object (universe or overload for example). When I start my process the memory used keep growing, starting for 20 mb to more than 100mb and if I have too many objec