How to Automate VLC player in perl?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Srijith B
    New Member
    • Jan 2011
    • 20

    How to Automate VLC player in perl?

    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

    Code:
    SYSTEM("vlc");
    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

    Code:
    #!usr/bin/perl
    
    #exec (vlc);
    #print "vlc launched";
    $directoryListing = `vlc`;
    print $directoryListing;            //opens vlc
    
    print "vlc playinng";
    
    my @keys = ("%{m}", "{ENTER}");
    for my $key (@keys){
    
    SendKeys ($key);
    }
    Problem here is once I execute, the statements after print $directoryListi ng; does not work.
  • RonB
    Recognized Expert Contributor
    • Jun 2009
    • 589

    #2
    You should have received the following error:
    Undefined subroutine &main::SYSTE M called at
    Perl is case sensitive.

    It's system not SYSTEM

    Comment

    • chorny
      Recognized Expert New Member
      • Jan 2008
      • 80

      #3
      Do a fork and run vlc in fork. `` waits for program to finish.

      Comment

      • Srijith B
        New Member
        • Jan 2011
        • 20

        #4
        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
        Code:
        #!usr/bin/perl
        $pid = fork();
        if( $pid == 0){
        system("vlc");
        exit 0;
        }
        print "vlc playinng";
        
         my @keys = ("%{m}", "{ENTER}");
         for my $key (@keys){
        SendKeys ($key);
        }

        Comment

        • miller
          Recognized Expert Top Contributor
          • Oct 2006
          • 1086

          #5
          The following example with fork does work for me, however, the script won't exit until vlc is closed.

          Code:
          #!usr/bin/perl
          
          use strict;
          
          my $vlc = q{C:\Program Files\VideoLAN\VLC\vlc.exe};
          
          unless (fork) {
          	system($vlc);
          	exit;
          }
          
          print "Hello world\n";
          Since you're running on a windows machine though, you have the option of using Win32::Process

          Code:
          #!usr/bin/perl
          
          use Win32::Process;
          
          use strict;
          
          my $vlc = q{C:\Program Files\VideoLAN\VLC\vlc.exe};
          
          Win32::Process::Create(
          	my $processobj,
          	$vlc,
          	"vlc",
          	0,
          	NORMAL_PRIORITY_CLASS,
          	"."
          ) or die "Can't Create - $!";
          
          print "Hello world\n";
          The above will start vlc, and continue to Hello World and exit, leaving vlc running.

          - Miller

          Comment

          • Srijith B
            New Member
            • Jan 2011
            • 20

            #6
            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::Pr ocess).
            But you know that we cant use these in linux.

            I am unaware of packages in linux that is to be used.

            Comment

            • miller
              Recognized Expert Top Contributor
              • Oct 2006
              • 1086

              #7
              Well, if all else fails, just use & to start the process as an independent daemon.

              Code:
              #!/usr/bin/perl-w
              # waitforme.pl
              
              use strict;
              
              my $log = 'waitforme.log';
              
              open my $fh, '>>', $log or die "$log, $!";
              for (1..5) {
              	print $fh scalar(localtime), " - $_\n";
              	sleep 2;
              }
              and the main script

              Code:
              #!/usr/bin/perl-w
              # dontwait.pl
              
              use strict;
              
              my $prog = q{perl waitforme.pl};
              
              system(qq{$prog &});
              
              print "Hello world\n";
              - Miller

              Comment

              Working...