C:尝试实现未命名的管道

时间:2015-05-25 19:57:37

标签: c linux bash ubuntu pipe

我正在尝试制作一个模拟终端无名管道的程序。例如,如果我想运行命令:

ls -l | grep'10'

将是:

./ pipes ls -l - grep'10'

(我用 - 而不是|)。

然而,我的程序不起作用,因为execvp失败(坏地址)。这对我来说似乎不可能。我究竟做错了什么?欢迎任何帮助!

# encoding: utf-8

class AvatarUploader < CarrierWave::Uploader::Base

  include CarrierWave::RMagick

  storage :file
  # storage :fog

  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  # Only allows jpg, jpeg, or png
  def extension_white_list
    %w(jpg jpeg png)
  end

  resize_to_limit(600, 600)

  version :profile do
    process :crop
    resize_to_fill(120, 120)
    def full_filename (for_file = model.file) 
      "profile.png" 
    end
  end

  version :timeline do
    process :crop
    resize_to_fill(50, 50)
    def full_filename (for_file = model.file) 
      "timeline.png" 
    end
  end

  version :navigation do
    process :crop
    resize_to_fill(20, 20)
    def full_filename (for_file = model.file) 
      "navigation.png" 
    end
  end

  def crop
    if model.crop_x.present?
      resize_to_limit(600, 600)
      manipulate! do |img|
        x = model.crop_x.to_i
        y = model.crop_y.to_i
        w = model.crop_w.to_i
        h = model.crop_h.to_i
        img.crop!(x, y, w, h)
      end
    end
  end

end

1 个答案:

答案 0 :(得分:0)

替换:

                   if (execvp(cmd, *argv) == -1)

由:

               if (execvp(cmd, argv) == -1)

注意:

a)你使用的警告水平是否足够高?

b)你必须添加一个&#34; #include&#34; for&#34; execvp&#34;。这样,编译器就会自己找到这个错误。

c)最后一个return语句必须是&#34;返回0&#34;。同样,编译器必须警告您这个主题。