How to call a shell command in our Perl script - Educative.io
文章推薦指數: 80 %
There are two ways to call a shell command from the Perl script. Syntax. We use the backticks ( `` ) syntax when we want to capture the output of the shell ... SolutionsEducativeEnterpriseEnablementplatformDevelopersLearnnewtechnologiesProductsCoursesforEnterpriseSuperchargeyourengineeringteamCoursesforIndividualsWorldclasscoursesOnboardingOnboardnewhiresfasterAssessmentsMeasureyourSkillScorePersonalizedLearningPlansPersonalizedPlansforyourgoalsProjectsBuildrealworldapplicationsAnswersTrustedAnswerstoDeveloperQuestionsPricingForEnterpriseTailoredforyourteamForIndividualsStayaheadofthecurveCoursesLogInJoin forfreeTrustedanswerstodeveloperquestionsTrustedAnswerstoDeveloperQuestionsRelatedTagsperlshellcommunitycreatorHowtocallashellcommandinourPerlscriptGuthaVamsiKrishnaGrokkingModernSystemDesignInterviewforEngineers&ManagersAceyourSystemDesignInterviewandtakeyourcareertothenextlevel.LearntohandlethedesignofapplicationslikeNetflix,Quora,Facebook,Uber,andmanymoreina45-mininterview.LearntheRESHADEDframeworkforarchitectingweb-scaleapplicationsbydeterminingrequirements,constraints,andassumptionsbeforedivingintoastep-by-stepdesignprocess. StartLearningOverviewTherearetwowaystocallashellcommandfromthePerlscript.SyntaxWeusethebackticks(``)syntaxwhenwewanttocapturetheoutputoftheshellcommand.Weprovidethecommandbetweenthebackticks.my$variableName=`provideyourcommandhere`Ifwedon'twanttocapturetheoutputoftheshellcommand,weusethesystemfunction,asshownbelow.Thesystemfunctionwilljustdisplaytheoutput.system("provideyourcommandhere")Example#usagebackticksmy$output=`ls-l`;print"------displaythecapturedoutputwithbackticks------\n";print$output;print"\n------displaytheoutputofdiskusagecommandwithsystem-------\n";#usageofsystemsystem("df-h");RunAshellcommandinPerlExplanationLine2:WecallashellcommandfromaPerlscript,usingbackticks,andcapturetheoutputinaPerlvariableoutput.Line4:Wedisplaytheoutputcapturedinline2.Line8:WecallashellcommandfromthePerlscriptusingthesystemfunction.Thesystemfunctiondisplaystheoutput.RELATEDTAGSperlshellcommunitycreatorCONTRIBUTORGuthaVamsiKrishnaLicense:CreativeCommons-Attribution-ShareAlike4.0(CC-BY-SA4.0)GrokkingModernSystemDesignInterviewforEngineers&ManagersAceyourSystemDesignInterviewandtakeyourcareertothenextlevel.LearntohandlethedesignofapplicationslikeNetflix,Quora,Facebook,Uber,andmanymoreina45-mininterview.LearntheRESHADEDframeworkforarchitectingweb-scaleapplicationsbydeterminingrequirements,constraints,andassumptionsbeforedivingintoastep-by-stepdesignprocess. StartLearningKeepExploringRelatedCoursesLearnin-demandtechskillsinhalfthetimeSOLUTIONSForEnterpriseForIndividualsForHR&ducativeSessionsEducativeAnswersABOUTUSOurTeamCareersHiringFrequentlyAskedQuestionsContactUsPressMOREGitHubStudentsScholarshipCourseCatalogEarlyAccessCoursesEarnReferralCreditsCodingInterview.comCopyright©2022Educative,Inc.Allrightsreserved.
延伸文章資訊
- 1Running external programs from Perl with system
Shell expansion. Let's say you have a program called checkfiles that can check the files listed o...
- 2How to call a shell command in our Perl script - Educative.io
There are two ways to call a shell command from the Perl script. Syntax. We use the backticks ( `...
- 3Recipe 19.6. Executing Commands Without Shell Escapes
You need to use a user's input as part of a command, but you don't want to allow the user to make...
- 4How can I call a shell command in my Perl script?
How to run a shell script from a Perl program. 1. Using system system($command, @arguments);. For...
- 5How to execute Unix/shell commands in a Perl script?
How to execute Unix/shell commands in a Perl script? · 1. exec”” · 2. system() · 3. Backticks “ o...