`
standalone
  • 浏览: 611428 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

How to invoke shell in perl and how to capture the error if any?

    博客分类:
  • perl
阅读更多
http://www.perlmonks.org/?node_id=57193

system("wc -l");
Will call the given command and return the return value of that command. This is usually not what you want, because most of the times wc -l will mean that you want to get the number of lines back from that call and not if that call was successful or not.


$nol = `wc -l`
The backticks call the command and return it's output into the variable (here $nol. In this case this will be what you want.
Another way of doing this is to use

$nol = qx/wc -l/;
(mnemonic: qx quote execute). I think is just the same as the backquotes (at least I don't know any difference)

Of course there are other ways (exec,fork) that behave different with respect to processes, but I don't know much about this.

And use $? to check the error code of backticks of system().
分享到:
评论

相关推荐

    How to invoke Java web service in ASP

    How to invoke Java web service in ASP

    How to invoke events across User Controls in ASP.NET

    if (MyCustomEvent != null) { MyCustomEvent(this, e); } } // 在适当的地方调用此方法 protected void Button_Click(object sender, EventArgs e) { // ...其他逻辑... OnMyCustomEvent(new ...

    How to invoke Java web service in ASP.net using C#.zip

    在IT行业中,跨平台通信是常见的需求,尤其是在Web服务领域。本教程将深入探讨如何在ASP.NET环境中,利用C#语言调用Java Web服务。Java Web服务通常采用SOAP(Simple Object Access Protocol)协议来实现互操作性,...

    2009 达内Unix学习笔记

    各个 shell 可互相切换 ksh:$ sh:$ csh:guangzhou% bash:bash-3.00$ 一、注意事项 命令和参数之间必需用空格隔开,参数和参数之间也必需用空格隔开。 一行不能超过256个字符;大小写有区分。 二、特殊字符...

    数据结构作业Hash表

    Note: the stl vector is used in this assignment, if you have any difficulties, you can refer to the documents given in this folder. Submission Submit only the following. 1. hashset.cpp – your ...

    C Programming

    - **Making Multiple Decisions**: Explanation of how the `switch` statement works and when it's appropriate to use it instead of nested `if` statements. #### Strings The document explains strings, ...

    android lint performance probe帮助.zip

    for how to set the org.gradle.jvmargs property.) Finally, invoke Lint from Gradle as you normally do. Once Lint finishes, performance statistics for each Lint detector should be printed to the console...

    How c# invoke dll

    在C#编程中,有时我们需要调用已存在于DLL(动态链接库)中的函数,以便利用它们的功能,而无需从头开始编写代码。`DllImport`特性就是C#提供的一种方法,让我们能够直接调用非托管DLL(通常是用C++或其他语言编写的...

    hash table spell checking

    Note: the stl vector is used in this assignment, if you have any difficulties, you can refer to the documents given in this folder. Submission Submit only the following. 1. hashset.cpp – your ...

    Apache Axis2 Web Services, 2nd Edition.pdf

    Chapter 9, The Client API - Learn how to use Axis2 to invoke other services, available APIs, and how to use them. Chapter 10, Session Management - Go beyond single invocation and learn how to use ...

    Android代码-poly-sample-android

    This is a sample project showing how to invoke the Poly API from an Android app. Note about rendering: The focus of this sample is showing how to call the Poly API, not showing how to render models. ...

    GWT in Action

    This chapter covers the use of the GWT module's XML configuration file to manage resources, alter project layout, invoke class replacement and generation, and include server components. It also ...

    Invoke-and-BeginInvoke.rar_The Difference_invoke

    在Windows Forms或WPF等UI环境中,由于UI元素(如控件)只能在其创建的线程(即UI线程)中进行修改,因此,当需要在后台线程更新UI时,`Invoke`和`BeginInvoke`就显得尤为重要。这两个方法都是`Control`类的成员,...

    MS-DOS 5.0

    below, you must add the specified /machine switch to the DEVICE=HIMEM.SYS command in your CONFIG.SYS file before you run Setup. After changing the CONFIG.SYS file, run Setup. System Switch ------ ...

    Functional C#[January 2017].pdf

    Before that, we discuss the use of the extension method and also discuss how to get this new method in IntelliSense. Also, we try to invoke the extension method from other assemblies. Chapter 5, ...

    How to make D.eval invoke the user-defined function callback

    if (result) { console.log('执行结果:', result); } else { console.error('错误:', error); } } // 调用dEval,传入代码和回调 dEval('2 + 2', myCallback); ``` 描述中提到的博客链接指向iteye上的一个...

    Salesforce doc: Integration Patterns and Practices

    **Pattern Summary**: This pattern describes how to update the user interface in real-time based on changes in the underlying data. It is useful for scenarios where users need to see updated ...

    Getting Started using PC-lint Plus

    If you encounter any issues or have questions during your evaluation, feel free to contact the support team at support@pclintplus.com. They'll be happy to assist you in making the most of PC-lint Plus...

    Turbo C++ 3.0[DISK]

    the compiler will search for test.cpp, and give an error if a file of that name cannot be found. If you want to have the command-line compiler assume a .c extension and C language source, use the ...

    Turbo C++ 3.00[DISK]

    the compiler will search for test.cpp, and give an error if a file of that name cannot be found. If you want to have the command-line compiler assume a .c extension and C language source, use the ...

Global site tag (gtag.js) - Google Analytics