How to call a shell command in our Perl script - Educative.io

文章推薦指數: 80 %
投票人數:10人

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.



請為這篇文章評分?