Loading ...
Sorry, an error occurred while loading the content.

Re: perl is freezing my gvim

Expand Messages
  • red@pixelearth.net
    ... Thanks for your input guys. This script works perfectly fine in all versions of vim and gvim EXCEPT if I have the following line of code: $proceed =
    Message 1 of 10 , Nov 2, 2007
    • 0 Attachment
      A.Politz wrote:
      red@... wrote:
      
        
      Ok, folks, I've found a workaround, but don't understand why it works.
      
      It turns out that I can run the script (!myscript args), let it hang,
      then manually kill the perl process that has hanged. Then, it seems for
      the life of my gvim session, the script will work as it should, with no
      <STDIN> issues. So the script only works once I've already killed the
      first perl process. Don't understand it, but it'll have to do for now....
      
      red@... wrote:
       
      
          
      Thanks for the suggestion, but ctrl-z freezes gvim up completely, so
      does shft-ctrl-z
      
      I've tried nearly every combination on the keyboard I can think of, so
      maybe there is a config setting that is the problem/solution.
      
      
      
         
      
            
      I think it would help people, if you would actually provide
      some details about what you are doing in your script.
      
      I imagine it is something like
      $str=<stdin>
      ???
      
      If so, does ':!perl -e '$s=<stdin>' in gvim return ?
      
      -ap
      
        

      Thanks for your input guys. This script works perfectly fine in all versions of vim and gvim EXCEPT if I have the following line of code:

              $proceed = <STDIN>;

      When I have this line of code, there is an issue with gvim under cygwin/x. I can't find a good way to let gvim know I'm done entering my input.

      Since you ask, the purpose of the script is to FTP the current buffer to any of several servers based on its location on my local machine. Like I said, I've found the workaround posted two messages back, but it's kind of inexplicable to me...

      Also since you asked, the gory code is below.


      #!/usr/bin/perl

      #use strict;
      use warnings;
      use Switch;
      use Net::FTP;

      # Config
      $TIMEOUT             = 20;                                    # max time to wait for ftp connect
      $LOCAL_HTDOCS_DIR     = '/cygdrive/c/apache2triad/htdocs/';     # all my websites start here

      @site_config_data     = (
          [
             'domain1.net',    # domain
          'user1',            # user
          'pw2',        # pw
          'local_root/',        # the dir just after $LOCAL_HTDOCS_DIR above. This is the local root that is synced with the remote web root.
          ],
          [
             'domain2.org',
          'user',
          'pw_00',
          'folder/',
          ],
      );

      print  "\n====================================== FTP RESULTS =========================================\n\n";
      #make sure we have a file to upload
      if (!$ARGV[0] or !$ARGV[1]) {
          die "Error: improper arguments sent. This script takes a local file to upload as its first arg, and the local path to that file as the second element. Currently this file is properly called like this in vim: :!up %:p %:p:h. This is a little ungainly, so put the mapping 'cab u :!up %:p %:p:h' in your .vimrc. \n";
      }

      # file info
      $local_file             = $ARGV[0];             # full path w/ file name
      $local_dir             = $ARGV[1];                # is just the path (no file name)

      # attempt to match the dir of the passed file with a dir in the config list
      foreach ($i=0; $i<@site_config_data; $i++)
      {
          $local_site_root = $LOCAL_HTDOCS_DIR . $site_config_data[$i][3];
          if (index($local_file, $local_site_root) > -1)
          {
              # assign config info
              $ftp_server    = $site_config_data[$i][0];
              $ftp_user_name = $site_config_data[$i][1];
              $ftp_user_pass = $site_config_data[$i][2];
              $remote_dir    = substr ($local_dir, length($local_site_root));

              print "\n Match found: \n\t $local_site_root \n\t $local_file    \n\n ";
              print "Will be uploaded to \n\t $ftp_server/$remote_dir \n\n";
             
              print "DOES THIS SEEM RIGHT, AND SHOULD I PROCEED WITH UPLOAD? (y|n)?";

              # get ok from user
              $proceed = <STDIN>;
              chomp ($proceed);

              # process user response.
              switch ($proceed) {
                  case 'n' {
                      print "\nAborting upload! \n";
                      exit;
                  } case 'y' {
                      print "\nProceeding to file upload...\n\n";
                  } else {
                      print ("\nNext time please type 'y' or 'n'. Aborting...");
                      exit;
                  }
              }
          }
      }

      # make sure we have a remote/local match before proceeding
      if (!$ftp_server) {
          die "No server configuration match found for: $local_file \nPerhaps you need to add this server's info to the config list? \n";
      }

      # connect
      $ftp = Net::FTP->new($ftp_server, Timeout=>$TIMEOUT) or die "could not connect to server ( $ftp_server )! $@";
      print "connected to server \t\t\t'$ftp_server'...\n";

      # login
      $ftp->login($ftp_user_name, $ftp_user_pass) or die "Could not login with user ( $ftp_user_name )", $ftp->message;
      print "logged into server as \t\t\t'$ftp_user_name'...\n";

      # go to dir
      $ftp->cwd($remote_dir) or die "Could not cwd to $remote_dir\n", $ftp->message;
      print "Successfull cwd to \t\t\t'$remote_dir'...\n";

      # upload file
      $ftp->put($local_file) or die "Can't put $local_file into $remote_dir\n", $ftp->message;
      print "uploaded file \t\t\t'$local_file'\n";



      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---

    Your message has been successfully submitted and would be delivered to recipients shortly.