469,282 Members | 2,025 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

How to Automate VLC player in perl?

Srijith B
I want to write a code in perl which automatically opens vlc player and start playing.

I am stuck when I open the vlc player.
I use

Expand|Select|Wrap|Line Numbers
  1. SYSTEM("vlc");
  2.  
But when I execute the lines below this code doesn't not execute.
Is there any other way to open vlc player?

ok, I changed my code
Here is it

Expand|Select|Wrap|Line Numbers
  1. #!usr/bin/perl
  2.  
  3. #exec (vlc);
  4. #print "vlc launched";
  5. $directoryListing = `vlc`;
  6. print $directoryListing;            //opens vlc
  7.  
  8. print "vlc playinng";
  9.  
  10. my @keys = ("%{m}", "{ENTER}");
  11. for my $key (@keys){
  12.  
  13. SendKeys ($key);
  14. }
  15.  
Problem here is once I execute, the statements after print $directoryListing; does not work.
Jan 18 '11 #1
6 4524
RonB
589 Expert Mod 512MB
You should have received the following error:
Undefined subroutine &main::SYSTEM called at
Perl is case sensitive.

It's system not SYSTEM
Jan 18 '11 #2
chorny
80 Expert
Do a fork and run vlc in fork. `` waits for program to finish.
Jan 26 '11 #3
I dont want to wait after I run vlc. I want the below statements to execute after the vlc is opened.
what I get is
The VLC will open and a message "[0x9bfa140] main libvlc: Running vlc with the default interface. Use 'cvlc' to use vlc without interface." appears in the terminal and the program is waiting for vlc to quit. once the vlc quits(CTRL +C or close vlc using mouse) the rest of the statements execute. Btw I tried forking and had no luck.. same result.
here the forking code
Expand|Select|Wrap|Line Numbers
  1. #!usr/bin/perl
  2. $pid = fork();
  3. if( $pid == 0){
  4. system("vlc");
  5. exit 0;
  6. }
  7. print "vlc playinng";
  8.  
  9.  my @keys = ("%{m}", "{ENTER}");
  10.  for my $key (@keys){
  11. SendKeys ($key);
  12. }
  13.  
  14.  
  15.  
Feb 28 '11 #4
miller
1,089 Expert 1GB
The following example with fork does work for me, however, the script won't exit until vlc is closed.

Expand|Select|Wrap|Line Numbers
  1. #!usr/bin/perl
  2.  
  3. use strict;
  4.  
  5. my $vlc = q{C:\Program Files\VideoLAN\VLC\vlc.exe};
  6.  
  7. unless (fork) {
  8.     system($vlc);
  9.     exit;
  10. }
  11.  
  12. print "Hello world\n";
  13.  
Since you're running on a windows machine though, you have the option of using Win32::Process

Expand|Select|Wrap|Line Numbers
  1. #!usr/bin/perl
  2.  
  3. use Win32::Process;
  4.  
  5. use strict;
  6.  
  7. my $vlc = q{C:\Program Files\VideoLAN\VLC\vlc.exe};
  8.  
  9. Win32::Process::Create(
  10.     my $processobj,
  11.     $vlc,
  12.     "vlc",
  13.     0,
  14.     NORMAL_PRIORITY_CLASS,
  15.     "."
  16. ) or die "Can't Create - $!";
  17.  
  18. print "Hello world\n";
  19.  
The above will start vlc, and continue to Hello World and exit, leaving vlc running.

- Miller
Mar 2 '11 #5
sorry for not mentioning the OS.
I am using Linux ubuntu.
I have a well running vlc automation script in windows.
And yes, I used the same package as the above(Win32::Process).
But you know that we cant use these in linux.

I am unaware of packages in linux that is to be used.
Mar 3 '11 #6
miller
1,089 Expert 1GB
Well, if all else fails, just use & to start the process as an independent daemon.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl-w
  2. # waitforme.pl
  3.  
  4. use strict;
  5.  
  6. my $log = 'waitforme.log';
  7.  
  8. open my $fh, '>>', $log or die "$log, $!";
  9. for (1..5) {
  10.     print $fh scalar(localtime), " - $_\n";
  11.     sleep 2;
  12. }
  13.  
and the main script

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl-w
  2. # dontwait.pl
  3.  
  4. use strict;
  5.  
  6. my $prog = q{perl waitforme.pl};
  7.  
  8. system(qq{$prog &});
  9.  
  10. print "Hello world\n";
  11.  
- Miller
Mar 3 '11 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Stephen Ferg | last post: by
1 post views Thread by Someone | last post: by
reply views Thread by Greg | last post: by
2 posts views Thread by Santosh | last post: by
4 posts views Thread by subeen | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.