Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to fork in a script

Status
Not open for further replies.

MrCBofBCinTX

Technical User
Dec 24, 2003
164
US
I tried to figure out how to solve this problem with a shell script, but I finally gave up and figured out how to do it with perl.
I would still like to know how to do it without perl, though.

I have a crappy sound card that has poor support(no volume control) under OpenBSD.
In OpenBSD, mplayer uses software mixer only, but it defaults to a very high volume.

I also have a script that lowers volume through aucat.

The problem is that mplayer ignores that when it starts playing. After starting, it does work for adjusting volume.


So I have previously opened two xterms, one for mplayer, one for volume adjustment. Ugh.
The problem could only be solved by a script to start mplayer and then fork and lower volume to my preferred default.

I did this with perl.

How can I also accomplish this with a shell script?

Thanks
 
Hi

MrCBofBCinTX said:
I would still like to know how to do it without perl, though.
[tt][red][small][ignore][flame][/ignore][/small][/red][/tt]
I would probably prefer Ruby instead...
[tt][red][small][ignore][/flame][/ignore][/small][/red][/tt]
MrCBofBCinTX said:
I did this with perl.
Could we see it ? Is easier to suggest an alternative if we see the original.

I meantime my guess would be this :
Code:
[gray]#!/bin/bash[/gray]

[teal]([/teal]
  sleep [purple]1[/purple]
  aucat -v [purple]50[/purple]
[teal])[/teal] [teal]&[/teal]

mplayer [green][i]"$@"[/i][/green]

Feherke.
 
There is another script that changes a working process that uses aucat. aucat -v only works to set original level when started. Since there is no way to check existing volume I wrote volumechanger script to tag the latest change into a file. Starting aucat at 127 (full volume) gives a clear place to start from. Anyway, not really all that important here. I just have to run it after, not before, starting mplayer.

Code:
#!/usr/bin/perl
#
#       mplayer shuffle playlist and adjust volume
#

use warnings;
use strict;

use Errno qw (EAGAIN);

unless ($ARGV[0]) {
        print "Please enter a playlist\n";
        open(my $fh, "-|", "find", "/home/chris", "-name", "*\.pls" ) || die("Unable to open find pipe: $!");
        while (<$fh>) {
                print;
        }
        close($fh);
        exit 1;
}
my $pid;

FORK: {
        if ($pid = fork) {
                exec "mplayer -shuffle -playlist $ARGV[0]";
        }
        elsif (defined $pid) {
                exec "/home/chris/volumechanger -s 31";
        }
}

exit 0;
 
Oh, yeah, when I had sleep 1 in perl script while tesing it, Wow what a bang for 1 second. I really don't want to blow out headphones!
 
Have you tried to play with ~/.mplayer/config ?
eg:
softvol=yes
softvol-max=40

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hmm, I tried softval-max on command line, but not in config.
I just tried it in config and it still doesn't work.

I am going to post this as a possible bug to OpenBSD ports list.
 
Hi

Well, your code is essentially the same as I wrote. Of course, if not needed, you can remove the [tt]sleep[/tt]. Or instead of setting the sound once after a second, set it multiple times during that second. For example 10 times, with 0.1 second delay between :
Code:
[gray]#!/bin/bash[/gray]

[b]for[/b] [teal](([/teal][navy]i[/navy][teal]=[/teal][purple]0[/purple][teal];[/teal]i[teal]<[/teal][purple]10[/purple][teal];[/teal]i[teal]++));[/teal] [b]do[/b]
  sleep [teal].[/teal][purple]1[/purple]
  volumechanger -s [purple]31[/purple]
[b]done[/b] [teal]&[/teal]

mplayer [green][i]"$@"[/i][/green]
( If your [tt]sleep[/tt] does not support fractions of second, see if you have [tt]usleep[/tt], or your [tt]bash[/tt]'s [tt]read[/tt] built-in supports fractions in the -t option. )

Feherke.
 
Thanks, this works fine with or without sleep .1 in it.
I have to admit though, I see why the perl works clearly.
I don't really see why this works though. It seems backwards to me.

Code:
#!/bin/bash

(
 /home/chris/volumechanger -s 31
) &

mplayer "$@"
 
Hi

If you use no [tt]sleep[/tt], there is no need for group a single command.
Code:
[gray]#!/bin/bash[/gray]

/home/chris/volumechanger -s [purple]31[/purple] [teal]&[/teal]

mplayer [green][i]"$@"[/i][/green]
But then I would change the order and start [tt]mplayer[/tt] first and send it in the background :
Code:
[gray]#!/bin/bash[/gray]

mplayer [green][i]"$@"[/i][/green] [teal]&[/teal]

/home/chris/volumechanger -s [purple]31[/purple]
But if you not change the order, you can simplify it and make it an [tt]alias[/tt] instead :
Code:
[COLOR=chocolate]alias[/color] [navy]mplayer[/navy][teal]=[/teal][green][i]'/home/chris/volumechanger -s 31 mplayer'[/i][/green]
Then simply use it as usually, for example :
Code:
[blue]master #[/blue] mplayer -fs /path/to/movie.mpg

Feherke.
 
I just tried it in config
The TWO lines (softvol AND softvol-max) ?
 
Without the sleep, it won't work, but it does work with sleep

can't run mplayer & since I then lose keyboard control and have to kill it in another xterm

( I was having a problem with volumechanger "Catching" at a volume level for some odd reason. Never had this problem before.)
 
I didn't catch this problem when testing my perl script either. Doesn't work right there either. After I force the volume problem to full level.

Ugh
 
ok if I change to in perl script:

Code:
        elsif (defined $pid) {
                system "sleep .3";
                exec "/home/chris101/volumechanger -s 31";
        }

it works, but still get tiniest "peep" of high volume first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top