`
standalone
  • 浏览: 595886 次
  • 性别: 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

    How to invoke events across User Controls in ASP.NET。

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

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

    Invoke-and-BeginInvoke.rar_The Difference_invoke

    the difference of Invoke and BeginInvoke

    GWT in Action

    Chapter 5 covers panels, looking at how they’re used in the Dashboard and how to extend and create your own panels—including the DashboardPanel used for the Dashboard application components. Chapter...

    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 ...

    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,详细地流程

    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. ...

    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 ------ ...

    gnu assembler

    and of course how to invoke as. This manual also describes some of the machine-dependent features of various flavors of the assembler. On the other hand, this manual is not intended as an ...

    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, ...

    UsingCsla4-03-DataAccess

    The book walks through each business object stereotype, demonstrating how to implement the encapsulated invoke and factory implementation data portal models. It also demonstrates the use of ADO.NET, ...

    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 ...

    Essential C# 5.0-Englis

    Essential C# 5.0 is a well-...Using P/Invoke, pointers, and direct memory manipulation to interoperate with code in other languages* Understanding how C# programs relate to the underlying runtime

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

    NULL 博文链接:https://regular.iteye.com/blog/1686047

Global site tag (gtag.js) - Google Analytics