精华内容
参与话题
问答
  • 成功解决ERROR: Command errored out with exit status 1: command: 'f:\program files\python\python36\pyt 解决问题 Building wheel for av (setup.py) ... error ERROR: Command errored out with exit ...

    成功解决ERROR: Command errored out with exit status 1:   command: 'f:\program files\python\python36\pyt

     

     

     

    目录

    解决问题

    解决方法


     

     

     

    解决问题

     

      Building wheel for av (setup.py) ... error
      ERROR: Command errored out with exit status 1:
       command: 'f:\program files\python\python36\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\niu\\AppData\\Local\\Temp\\pip-install-5rnmsd35\\av\\setup.py'"'"'; __file__='"'"'C:\\Users\\niu\\AppData\\Local\\Temp\\pip-install-5rnmsd35\\av\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\niu\AppData\Local\Temp\pip-wheel-petvhosf' --python-tag cp36
           cwd: C:\Users\niu\AppData\Local\Temp\pip-install-5rnmsd35\av\
      Complete output (36 lines):
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build\lib.win-amd64-3.6
      creating build\lib.win-amd64-3.6\av
      copying av\datasets.py -> build\lib.win-amd64-3.6\av
      copying av\deprecation.py -> build\lib.win-amd64-3.6\av
      copying av\__init__.py -> build\lib.win-amd64-3.6\av
      copying av\__main__.py -> build\lib.win-amd64-3.6\av
      creating build\lib.win-amd64-3.6\av\audio
      copying av\audio\__init__.py -> build\lib.win-amd64-3.6\av\audio
      creating build\lib.win-amd64-3.6\av\codec
      copying av\codec\__init__.py -> build\lib.win-amd64-3.6\av\codec
      creating build\lib.win-amd64-3.6\av\container
      copying av\container\__init__.py -> build\lib.win-amd64-3.6\av\container
      creating build\lib.win-amd64-3.6\av\data
      copying av\data\__init__.py -> build\lib.win-amd64-3.6\av\data
      creating build\lib.win-amd64-3.6\av\filter
      copying av\filter\__init__.py -> build\lib.win-amd64-3.6\av\filter
      creating build\lib.win-amd64-3.6\av\subtitles
      copying av\subtitles\__init__.py -> build\lib.win-amd64-3.6\av\subtitles
      creating build\lib.win-amd64-3.6\av\video
      copying av\video\__init__.py -> build\lib.win-amd64-3.6\av\video
      running build_ext
      running config
      writing build\temp.win-amd64-3.6\Release\include\pyav\config.h
      running cythonize
      building 'av.buffer' extension
      creating build\temp.win-amd64-3.6\Release\src
      creating build\temp.win-amd64-3.6\Release\src\av
      D:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Iinclude "-If:\program files\python\python36\include" -Ibuild\temp.win-amd64-3.6\Release\include "-If:\program files\python\python36\include" "-If:\program files\python\python36\include" -Ibuild\temp.win-amd64-3.6\Release\include "-ID:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-ID:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\\shared" "-IC:\Program Files (x86)\Windows Kits\8.1\include\\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\\winrt" /Tcsrc\av\buffer.c /Fobuild\temp.win-amd64-3.6\Release\src\av\buffer.obj
      buffer.c
      D:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO "/LIBPATH:f:\program files\python\python36\libs" "/LIBPATH:f:\program files\python\python36\PCbuild\amd64" "/LIBPATH:f:\program files\python\python36\libs" "/LIBPATH:f:\program files\python\python36\PCbuild\amd64" "/LIBPATH:D:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64" "/LIBPATH:D:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\LIB\amd64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.10240.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\lib\um\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x64" avdevice.lib avutil.lib avfilter.lib swresample.lib avformat.lib swscale.lib avcodec.lib /EXPORT:PyInit_buffer build\temp.win-amd64-3.6\Release\src\av\buffer.obj /OUT:build\lib.win-amd64-3.6\av\buffer.cp36-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.6\Release\src\av\buffer.cp36-win_amd64.lib /OPT:NOREF
      LINK : fatal error LNK1181: 无法打开输入文件“avdevice.lib”
      error: command 'D:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\link.exe' failed with exit status 1181
      ----------------------------------------
      ERROR: Failed building wheel for av
      Running setup.py clean for av
    Failed to build av
    Installing collected packages: av
        Running setup.py install for av ... error
        ERROR: Command errored out with exit status 1:
         command: 'f:\program files\python\python36\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\niu\\AppData\\Local\\Temp\\pip-install-5rnmsd35\\av\\setup.py'"'"'; __file__='"'"'C:\\Users\\niu\\AppData\\Local\\Temp\\pip-install-5rnmsd35\\av\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\niu\AppData\Local\Temp\pip-record-4xd1oct7\install-record.txt' --single-version-externally-managed --compile
             cwd: C:\Users\niu\AppData\Local\Temp\pip-install-5rnmsd35\av\
        Complete output (36 lines):
        running install
        running build
        running build_py
        creating build
        creating build\lib.win-amd64-3.6
        creating build\lib.win-amd64-3.6\av
        copying av\datasets.py -> build\lib.win-amd64-3.6\av
        copying av\deprecation.py -> build\lib.win-amd64-3.6\av
        copying av\__init__.py -> build\lib.win-amd64-3.6\av
        copying av\__main__.py -> build\lib.win-amd64-3.6\av
        creating build\lib.win-amd64-3.6\av\audio
        copying av\audio\__init__.py -> build\lib.win-amd64-3.6\av\audio
        creating build\lib.win-amd64-3.6\av\codec
        copying av\codec\__init__.py -> build\lib.win-amd64-3.6\av\codec
        creating build\lib.win-amd64-3.6\av\container
        copying av\container\__init__.py -> build\lib.win-amd64-3.6\av\container
        creating build\lib.win-amd64-3.6\av\data
        copying av\data\__init__.py -> build\lib.win-amd64-3.6\av\data
        creating build\lib.win-amd64-3.6\av\filter
        copying av\filter\__init__.py -> build\lib.win-amd64-3.6\av\filter
        creating build\lib.win-amd64-3.6\av\subtitles
        copying av\subtitles\__init__.py -> build\lib.win-amd64-3.6\av\subtitles
        creating build\lib.win-amd64-3.6\av\video
        copying av\video\__init__.py -> build\lib.win-amd64-3.6\av\video
        running build_ext
        running config
        writing build\temp.win-amd64-3.6\Release\include\pyav\config.h
        running cythonize
        building 'av.buffer' extension
        creating build\temp.win-amd64-3.6\Release\src
        creating build\temp.win-amd64-3.6\Release\src\av
        D:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Dinline=__inline -Iinclude -Ibuild\temp.win-amd64-3.6\Release\include "-If:\program files\python\python36\include" "-If:\program files\python\python36\include" "-If:\program files\python\python36\include" -Ibuild\temp.win-amd64-3.6\Release\include "-ID:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-ID:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\\shared" "-IC:\Program Files (x86)\Windows Kits\8.1\include\\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\\winrt" /Tcsrc\av\buffer.c /Fobuild\temp.win-amd64-3.6\Release\src\av\buffer.obj
        buffer.c
        D:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO "/LIBPATH:f:\program files\python\python36\libs" "/LIBPATH:f:\program files\python\python36\PCbuild\amd64" "/LIBPATH:f:\program files\python\python36\libs" "/LIBPATH:f:\program files\python\python36\PCbuild\amd64" "/LIBPATH:D:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64" "/LIBPATH:D:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\LIB\amd64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.10240.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\lib\um\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x64" swscale.lib swresample.lib avcodec.lib avformat.lib avdevice.lib avutil.lib avfilter.lib /EXPORT:PyInit_buffer build\temp.win-amd64-3.6\Release\src\av\buffer.obj /OUT:build\lib.win-amd64-3.6\av\buffer.cp36-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.6\Release\src\av\buffer.cp36-win_amd64.lib /OPT:NOREF

     

     

    解决方法

    T1、改为wheel文件进行下载
    T2、其他方法寻找中……

     

     

     

     

     

     

     

     

     

    展开全文
  • python安装第三方库遇到 ERROR: Command errored out with exit status 1:…的问题 先来看看错误提示: 本来想用python弄个词云玩玩,没想到在安装wordcloud库的时候居然给我这一大串红叉叉,很是奔溃,出师不利啊!...

    python安装第三方库遇到 ERROR: Command errored out with exit status 1:…的问题

    先来看看错误提示:
    本来想用python弄个词云玩玩,没想到在安装wordcloud库的时候居然给我这一大串红叉叉,很是奔溃,出师不利啊!
    在这里插入图片描述
    报错的部分内容如下:
    ERROR: Command errored out with exit status 1:
    command: ‘c:\users\15870\appdata\local\programs\python\python37-32\python.exe’ -u -c ‘import sys, setuptools, tokenize; sys.argv[0] = ‘"’"‘C:\Users\15870\AppData\Local\Temp\pip-install-2wcyweho\wordcloud\setup.py’"’"’; file=’"’"‘C:\Users\15870\AppData\Local\Temp\pip-install-2wcyweho\wordcloud\setup.py’"’"’;f=getattr(tokenize, ‘"’"‘open’"’"’, open)(file);code=f.read().replace(’"’"’\r\n’"’"’, ‘"’"’\n’"’"’);f.close();exec(compile(code, file, ‘"’"‘exec’"’"’))’ install --record ‘C:\Users\15870\AppData\Local\Temp\pip-record-9qx3thr5\install-record.txt’ --single-version-externally-managed --compile

    说实话作为一个渣渣新手,我是真的是看不懂这是个啥错误,但是,没关系,做为非专业人人士搞不懂错因也问题不大,能解决问题就行了,于是,经过一番查询,算是找到一个解决方法如下:

    1. 先打开python看看自己的python是什么版本的,多少位的。像我的就是3.7.3版本32位;
      在这里插入图片描述

    2. 去https://www.lfd.uci.edu/~gohlke/pythonlibs/找到对应版本的whl文件,我的话就是找wordcloud-1.5.0-cp37-cp37m-win32.whl这一个,其中cp37代表3.7版本,win32代表Windows系统32位机。
      在这里插入图片描述

    3. 下载对应的whl文件后,在cmd下进入whl所在的文件夹
      在这里插入图片描述 在这里插入图片描述

    4. 最后再输入pip install wordcloud-1.5.0-cp37-cp37m-win32.whl进行安装就可以了。
      在这里插入图片描述

    最后就可以用了,希望对大家能有帮助!

    展开全文
  • Python报错ERROR: Command errored out with exit status 1:

    万次阅读 多人点赞 2019-08-22 16:12:59
    因为Pycharm最近老是弹出RELP COMMUNICATIONS,非常影响代码运行的效率。 REPL(Read-Eval-Print Loop),翻译过来就是“读取-求值-输出”循环,是一个简单的...ERROR: Command errored out with exit status 1: ...

    2020.08.24更新:似乎产生这个的原因,就是因为Python 2和Python 3默认的编码格式不一样。

    Python 2是GBK,而Python 3是UTF-8。所以有些老旧的包在安装时,会产生编码的问题。


     因为Pycharm最近老是弹出RELP COMMUNICATIONS,非常影响代码运行的效率。

    REPL(Read-Eval-Print Loop),翻译过来就是“读取-求值-输出”循环,是一个简单的交互式的编程环境。

    听起来似乎挺有用,所以想直接在Pycharm中pip这个REPL。

    结果报错:

    ERROR: Command errored out with exit status 1:

     

    主要错误显示在最后几行:

    UnicodeDecodeError: 'gbk' codec can't decode byte 0xa6 in position 1246: illegal multibyte sequence
        ----------------------------------------
    ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

    定位问题:

    UnicodeDecodeError,表明是编码的问题。

    具体就是在setup.py文件中的第10行和第17行,读取文件的编码方式为GBK,而并非UTF-8,因此报错使得无法安装。


    更新成功解决的方法:

    由于不能使用 Pycharm 里的 Project Interpreter。

    解决思路:下载源码的包,进行代码改动之后install。

    1、找到原始package的文件,找到报错的那一行。

    REPL的官方地址是:https://github.com/mbr/repl。查看报错的setup文件的源码。

    定位问题:源码中没有指定open时的编码方式,使得默认为gbk编码。

    报错的源码:

    def read(fname):
        return open(os.path.join(os.path.dirname(__file__), fname)).read()

     

    2、下载原始包文件后,解压找到setup.py文件,修改文件里的这一行,即加上encoding='utf-8',保存后打包为新的安装包。

    修改后的代码:

    def read(fname):
        return open(os.path.join(os.path.dirname(__file__), fname),encoding='utf-8').read()

     

    3、输入 pip install repl-1.0.tar.gz,用新的安装包来进行install。成功!


    这个问题困扰了我一周,后来发现其实解决方法非常简单!

    解决问题最重要的是要定位报错产生的原因,然后根据原因一步步找到解决的方法。

    展开全文
  • 命令模式(Command Pattern) 命令模式属于行为型模式,它尝试将一个请求封装成一个对象,从而使您可以用不同的请求对客户进行参数化。 在该设计模式中,请求以命令的形式包裹在对象中并传给调用对象。调用对象寻找...

    命令模式(Command Pattern)

    命令模式属于行为型模式,它尝试将一个请求封装成一个对象,从而使您可以用不同的请求对客户进行参数化。

    在该设计模式中,请求以命令的形式包裹在对象中并传给调用对象。调用对象寻找可以处理该命令的合适的对象,并把该命令传给相应的对象请求执行。

    角色

    1、抽象命令(Command)

    定义命令的接口,声明命令执行的方法;

    2、具体命令(Concrete Command)

    命令接口实现对象,需要维持对接收者的引用,并调用接收者的功能来完成命令要执行的操作;

    3、接收者(Receiver)

    真正执行命令的对象。任何类都可能成为一个接收者,只要它能够实现命令要求实现的相应功能;

    4、调用者(Invoker)

    要求命令对象执行请求,需要维持命令对象的引用,可以持有很多的命令对象。

    示例

    在这里插入图片描述
    命名空间CommandPattern中包含Command基类、发票开具命令类CreateCommand、发票作废命令类CancelCommand、发票打印命令类PrintCommand、命令参数基类CommandArgs、发票开具命令参数类CommandArgs、发票作废命令参数类CancelArgs、发票打印命令参数类PrintArgs、接收者类Receiver和调用者类Invoker。本命尝试通过客户端调用不同的参数化发票命令来使调用者调用不同的功能。

    public abstract class Command {
    
        protected Receiver _receiver = null;
    
        protected CommandArgs _commandArgs = null;
    
        public Command(Receiver receiver, CommandArgs commandArgs) {
            this._receiver = receiver;
            this._commandArgs = commandArgs;
        }
    
        public abstract void Action();
    
    }
    

    抽象命令基类,包含Action动作执行命令,并且维持对接受者和命令参数的引用。

    public class CreateCommand : Command {
    
        public CreateCommand(Receiver receiver, CommandArgs commandArgs)
            : base(receiver, commandArgs) {
    
        }
    
        public override void Action() {
            _receiver.CommandArgs = _commandArgs;
            (_receiver as CreateReceiver)?.CreateInvoice();
        }
    
    }
    

    这是发票开具命令,由于基类维持了对调用者的引用,所以在Action方法中通过调用CreateInvoice方法来开具一张发票。

    public class CancelCommand : Command {
    
        public CancelCommand(Receiver receiver, CommandArgs commandArgs)
            : base(receiver, commandArgs) {
    
        }
    
        public override void Action() {
            _receiver.CommandArgs = _commandArgs;
            (_receiver as CancelReceiver)?.CancelInvoice();
        }
    
    }
    

    这是发票作废命令,由于基类维持了对调用者的引用,所以在Action方法中通过调用CancelInvoice方法来作废一张发票。

    public class PrintCommand : Command {
    
        public PrintCommand(Receiver receiver, CommandArgs commandArgs)
            : base(receiver, commandArgs) {
    
        }
    
        public override void Action() {
            _receiver.CommandArgs = _commandArgs;
            (_receiver as PrintReceiver)?.PrintInvoice();
        }
    
    }
    

    这是发票打印命令,由于基类维持了对调用者的引用,所以在Action方法中通过调用PrintInvoice方法来打印一张发票。

    public class CommandArgs {
    
        public string InvoiceType { get; set; }
    
    }
    
    public class CreateArgs : CommandArgs {
    
        public DateTime BillingDate { get; set; }
    
    }
    
    public class CancelArgs : CommandArgs {
    
        public string InvoiceCode { get; set; }
        public int InvoiceNumber { get; set; }
        public string CancelReason { get; set; }
        public string CancelMan { get; set; }
        public DateTime CancelDate { get; set; }
    
    }
    
    public class PrintArgs : CommandArgs {
    
        public string InvoiceCode { get; set; }
        public int InvoiceNumber { get; set; }
    
    }
    

    参数化的命令参数基类CommandArgs和它的3个具体实现类。实际开发过程中可以将参数化命令信息封装在具体命令类中,本例为了更好的扩展性,将参数化命令信息抽象出来。

    public class Invoker {
    
        private Command _command = null;
    
        public Invoker(Command command) {
            this._command = command;
        }
    
        public void Execute() {
            _command.Action();
        }
    
    }
    

    调用者类Invoker,实际开发中这个应为具体的调用类。例如我们需要从MQ获取实时数据,并根据从MQ获取到的JSON数据来处理不同的命令,那么这个调用者类应该为MQ所在的管理类(假如名为ActiveMQManager)。这时我们需要在ActiveMQManager类中维持对命令基类的引用,并在收到不同的JSON数据时解析出相应命令和命令参数信息,然后执行命令中的Action方法。

    public abstract class Receiver {
    
        public CommandArgs CommandArgs { get; set; }
    
        protected const string LINE_BREAK =
            "-------------------------" +
            "-------------------------";
        //文章排版需要,故折成2行
    
    }
    
    public class CreateReceiver : Receiver {
     
        public void CreateInvoice() {
            var args = CommandArgs as CreateArgs;
            if (args == null) throw new InvalidOperationException();
            Console.WriteLine("Create Invoice!");
            Console.WriteLine(
                $"InvoiceType is {args.InvoiceType},{Environment.NewLine}" +
                $"BillingDate is {args.BillingDate.ToString("yyyy-MM-dd HH:mm:ss")}!");
            Console.WriteLine(LINE_BREAK);
        }
     
    }
    
    public class CancelReceiver : Receiver {
     
        public void CancelInvoice() {
            var args = CommandArgs as CancelArgs;
            if (args == null) throw new InvalidOperationException();
            Console.WriteLine("Cancel Invoice!");
            Console.WriteLine(
                $"InvoiceCode is {args.InvoiceCode},{Environment.NewLine}" +
                $"InvoiceNumber is {args.InvoiceNumber},{Environment.NewLine}" +
                $"InvoiceType is {args.InvoiceType},{Environment.NewLine}" +
                $"CancelReason is {args.CancelReason},{Environment.NewLine}" +
                $"CancelMan is {args.CancelMan},{Environment.NewLine}" +
                $"CancelDate is {args.CancelDate.ToString("yyyy-MM-dd HH:mm:ss")}!");
            Console.WriteLine(LINE_BREAK);
        }
     
    }
    
    public class PrintReceiver : Receiver {
     
        public void PrintInvoice() {
            var args = CommandArgs as PrintArgs;
            if (args == null) throw new InvalidOperationException();
            Console.WriteLine("Print Invoice!");
            Console.WriteLine(
                $"InvoiceCode is {args.InvoiceCode},{Environment.NewLine}" +
                $"InvoiceNumber is {args.InvoiceNumber},{Environment.NewLine}" +
                $"InvoiceType is {args.InvoiceType}!");
            Console.WriteLine(LINE_BREAK);
        }
     
    }
    

    接收者基类Receiver和它的3个具体接收者类,需要维持对命令参数基类的引用,以便我们可以获取相应信息。接收者基类并不是命令模式必须的,但考虑到里氏替换原则和开闭原则,我们引入接收者基类并在不同的实现类里解耦不同的命令操作。

    public class Program {
    
        private static Receiver _receiver = null;
    
        public static void Main(string[] args) {
            _receiver = new CreateReceiver();
            Command command = new CreateCommand(
                _receiver, new CreateArgs {
                    InvoiceType = "004",
                    BillingDate = DateTime.UtcNow
                });
    
            var invoker = new Invoker(command);
            invoker.Execute();
    
            _receiver = new CancelReceiver();
            command = new CancelCommand(
                _receiver, new CancelArgs {
                    InvoiceCode = "310987289304",
                    InvoiceNumber = 34156934,
                    InvoiceType = "007",
                    CancelReason = "Invoice missing!",
                    CancelMan = "Iori",
                    CancelDate = DateTime.UtcNow
                });
    
            invoker = new Invoker(command);
            invoker.Execute();
    
            _receiver = new PrintReceiver();
            command = new PrintCommand(
                _receiver, new PrintArgs {
                    InvoiceCode = "310987289304",
                    InvoiceNumber = 34156934,
                    InvoiceType = "026"
                });
    
            invoker = new Invoker(command);
            invoker.Execute();
    
            Console.ReadKey();
        }
    
    }
    

    以上是为了测试本案例所编写的代码,通过不同的命令并提供额外的参数化命令信息来执行不同的功能。以下是这个案例的输出结果:

    Create Invoice!
    InvoiceType is 004,
    BillingDate is 2018-07-19 05:34:45!
    --------------------------------------------------
    Cancel Invoice!
    InvoiceCode is 310987289304,
    InvoiceNumber is 34156934,
    InvoiceType is 007,
    CancelReason is Invoice missing!,
    CancelMan is Iori,
    CancelDate is 2018-07-19 05:34:45!
    --------------------------------------------------
    Print Invoice!
    InvoiceCode is 310987289304,
    InvoiceNumber is 34156934,
    InvoiceType is 026!
    --------------------------------------------------
    

    优点

    1、降低对象之间的耦合度,通过参数化的命令信息来驱动程序的运行;
    2、新的命令可以很容易地加入到系统中;
    3、可以比较容易地设计一个组合命令;
    4、调用同一方法实现不同的功能。

    缺点

    使用命令模式可能会导致某些系统有过多的具体命令类,导致子类膨胀。

    使用场景

    1、系统需要将请求调用者和请求接收者解耦,使得调用者和接收者不直接交互;
    2、系统需要在不同的时间指定请求、将请求排队和执行请求;
    3、系统需要支持命令的撤销(Undo)操作和恢复(Redo)操作。

    展开全文
  • Design Pattern - Command(C#)

    万次阅读 多人点赞 2019-02-11 15:59:07
    分享一个大牛的人工智能教程。零基础!通俗易懂!风趣幽默!希望你也加入到人工智能的队伍中来!... Definition Encapsulate a request as an object, thereby letting you parameterize clients with different ...
  • ftp 500 Illegal EPRT command

    2013-12-23 08:02:17
    500 Illegal EPRT command 500 Illegal PORT command ftp: bind: Address already in use ftp> passive Passive mode: on; fallback to active mode: on. ftp> ls 227 Entering Passive Mode (10,65,1,157,238...
  • springboot(spring也一样的)整个redis 的时候报如下错误:org.springframework.dao.QueryTimeoutException: Redis command timed out; nested exception is io.lettuce.core.RedisCommandTimeoutException: ...
  • File "/tmp/pip-build-G9yO9Z/tldr/setuptools_scm-3.3.3-py2.7.egg/setuptools_scm/integration.py", line 9, in version_keyword File "/tmp/pip-build-G9yO9Z/tldr/setuptools_scm-3.3.3-py2.7.egg/setupt...
  • 0x00 前言 文章中的文字可能存在语法错误以及...1.前几次还好用的命令,这次再输入就出现-bash: ***: command not found的情况; 2.第一次使用就出现 -bash: ** : command not found的情况。 导致这种问题的原...
  • 解决mvn command not found

    万次阅读 2017-01-05 10:47:20
    环境变量是这样写: export JAVA_HOME=/usr/java/jdk1.8.0_111 export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export M3_HOME=/usr/local/maven3 export PATH=$JAVA_HOME/bin:$M3_...
  • 我在HKEY_CLASSES_ROOT\AllFilesystemObjectsAllFilesystemObjects下创建了自定义的菜单子健“test”,在command里添加了对我自定义的程序调用,内容为“D:/test.exe %1”,从而实现了在任意文件下点击鼠标右键后...
  • 解决mac安装homebrew后报错-bash: brew: command not found

    万次阅读 多人点赞 2016-09-18 10:32:36
    参照官网上很简单的一句安装命令, /usr/bin/ruby -e "...安装完毕后,发现使用brew命令,却总是提示:-bash: brew: command not found 于是怀疑安装过程出现问题,打算重装,重装却报: ...
  • Command line is too long.Shorten command line for Application or also for Spring Boot default configuration. 二、报错原因 springboot项目启动命令过长 三、解决办法 点击项目启动配置项 -> short.....
  • CentOS解决-bash: vim: command not found

    万次阅读 2019-04-16 13:52:31
    那么如何安裝 vim 呢? 输入rpm -qa|grep vim 命令, 如果 vim 已经正确安裝,会返回下面的三行代码: root@server1 [~]# rpm -qa|grep vim vim-enhanced-7.0.109-7.el5 vim-minimal-7.0.109-7.el5 ...
  • /Users/lixiuming/Ant/bin/ant: line 28: uname: command not found /Users/lixiuming/Ant/bin/ant: line 29: uname: command not found /Users/lixiuming/Ant/bin/ant: line 65: sed: command not found /Users/...
  • 解决:bash: make: command not found

    万次阅读 2017-06-19 15:44:17
    一般出现这个-bash: make: command not found提示,是因为安装系统的时候使用的是最小化mini安装,系统没有安装make、vim等常用命令,直接yum安装下即可。 yum -y install gcc automake autoconf libtool make
  • --------------------------------------------------------------------------------------------------------------------------------------------------------------------- 查看有无yum安装包 ,有的话卸载...
  • -bash: wget: command not found解决方法

    万次阅读 2019-05-14 13:56:46
    -bash: wget: command not found 很显然,问题出现的原因是由于没有安装wget命令,可以通过以下两种方法来安装: 1、rpm安装 wget的RPM包下载地址:http://www.rpmfind.net/linux/rpm2html/search.php?query=wget...
  • command1&&command2||command3

    千次阅读 2017-03-24 15:14:20
    类似于C++中的?: 若command1为真,则执行command2,否则执行command3 a=1 [ $a -eq 1 ]&&b=1||b=2 echo $b 输出: 1 (&&是前者为真再执行后者,||是前者执行失败再执行后者)
  • Java 连接redis集群报错提示 ERR unknown command 'SENTINEL'?怎么解决呢! 连接集群的代码在这里https://github.com/warmbreeze/sharded-jedis-sentinel-pool Exception in thread "main" redis.clients.jedis....
  • Java之command模式

    千次阅读 多人点赞 2015-11-24 17:27:31
    对于本篇文章,送给那些有部分代码经验的新手,因为我也是新手,如有...言归正传,先把话题扯到command模式来,举一个很简单的例子,前几天去餐馆吃饭,对服务员点了一份红烧肉一份牛肉,此刻,服务员会在菜单上面把
  • mac 终端下,执行以下命令,即可安装brew: /usr/bin/ruby -e "$(curl -fsSL ... 在终端环境下,brew --version 查看brew的版本,也可以验证brew是否安装成功 ...
  • 安装 brew command not found

    万次阅读 2019-08-14 17:36:02
    -bash: brew: command not found 解决 有两种原因,一种是不在path目录下,一种是没有安装。 首先安装一下试试: /usr/bin/ruby -e "$(curl -fsSL ...
  • `/bin/sh: rm: command not found` * 代码 ```` FROM centos:latest MAINTAINER my ENV PATH /tmp WORKDIR $PATH RUN rm -rf /tmp CMD /bin/bash ```` * Build过程 ``` Sending build ...
  • 设计模式之 command

    千次阅读 2010-07-24 08:22:00
    command这种方式我非常喜欢,觉得这样把处理和invoke分开了,挺好。 它的想法是,以MFC的UI操作为例。当用户单击一个按钮的时候,以前的做法是直接在OnClickButton中处理这个事情,当然,代码 也是...
  • 背景前言: 昨天买了一块高漫WH...那就是Command line option syntax error. Type Command /? for Help. what?? 什么鬼.为什么会这样,!! OK经过各种度娘.说是安装路径有中文名称.好吧奶奶个腿; 仔细检查没有啊,...
  • ON_COMMAND_RANGE和ON_UPDATE_COMMAND_UI_RANGE

    千次阅读 2005-10-26 17:16:00
    ON_COMMAND_RANGE 和 ON_UPDATE_COMMAND_UI_RANGE 可以影射ID连续的Toolbar/Menu ID。ON_COMMAND_RANGE影射的消息响应函数需要一个参数UINT表明是哪一个消息,afx_msg void OnZoom(UINT nID);而ON_UPDATE_COMMAND_UI...
  • redisCommand

    千次阅读 2018-05-15 11:39:21
    它是一个数组,数组的元素类型是redisCommand结构体。redisCommand是在src/redis.h中定义的。在redisCommandTable的上方有一块比较详细的注释,对它的每一个field做了解释。下面是get命令的定义:C{"get",...
  • WPF command

    千次阅读 2017-08-21 14:54:34
    1. 基本知识微软预定义了5类100多个常用命令: ApplicationCommands, NavigationCommands, MediaCommands, EditingCommands and ComponentCommands.命令的好处: 1).一处定义,到处使用(menu item, toolbar, ...
  • 安装 mysqlclient 时候 报错:error: command 'gcc' failed with exit status 1 以下是错误信息: Collecting mysqlclient Using cached mysqlclient-1.3.10.tar.gz Installing collected packages: mysqlclient ...

空空如也

1 2 3 4 5 ... 20
收藏数 221,017
精华内容 88,406
关键字:

command