473,387 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how to invoke/run a shell file sample.sh from within perl file.

Hello All,

I am new to perl. I have to write some code in perl on windows.

I have to invoke/run a shell file sample.sh from within perl file.
When the perl while is executing, it should run to set some env variables.

Another requirement is that:
I want to invoke cygwin shell from perl and then run some commands like cd, ls on the cygwin window. All this to be done by invoking through the running perl script.

OR

Any pointers on how to invoke ant target on windows from within perl script running on windows OS.

Please help.
Thanks in advance,
Prakash
May 30 '07 #1
2 6071
prn
254 Expert 100+
Hello, Prakash,

I have to invoke/run a shell file sample.sh from within perl file.
When the perl while is executing, it should run to set some env variables.
I'm not so sure about exactly what happens here on windows, but this is a notoriously common problem and it does not generally give you what you wanted. Generally speaking, you probably won't want to use a shell script to do this. For the rarer case where you really do need to invoke a shell script, we did have a recent thread about this and one poster, bidoun, proposed an interesting workaround (see posts #5 and #6). This may help. And even if it turns out that you don't really need to run the shell script, the illustration of how to accomplish the equivalent in Perl may help you.

I want to invoke cygwin shell from perl and then run some commands like cd, ls on the cygwin window. All this to be done by invoking through the running perl script.

OR

Any pointers on how to invoke ant target on windows from within perl script running on windows OS.
Perl has built-in functionality to do the job of cd and ls. Shelling out to do cd has the same problem that using a separate shell script to set environment variables has -- it does it in a separate process that does not propagate changes back to the parent process. Instead of that, use the built-in perl function chdir. As an ls equivalent, there are a number of ways to do similar things, depending on exactly how you want your data returned. Check out the glob function as well as the readdir function. You can look at this thread for some examples.

In general you can run just about anything with the system function, but it doesn't always do what you think it might do if you don't understand what you are doing. In particular, if you expect it to change the state of the process running the perl, then you are likely to be disappointed.

In general, it's better to ask (yourself or others) questions like "How can I best accomplish X?" than questions like "How can I use Y?"

HTH,
Paul
May 30 '07 #2
KevinADC
4,059 Expert 2GB
short answer: qx/STRING/ or `STRING`

regular expression quote-like operators


long answer: see prn's post
May 30 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Mohsin | last post by:
Hi all, I have a perl program which makes a user exit to the O/S (unix, solaris) to issue a O/S command. I know that the shell it invokes is NOT a korn shell, because I captured the shell info...
0
by: Kyle | last post by:
To any who chose to provide an answer, or even any suggestions to this problem, I thank you greatly in advance. +200 pts. for any valid solutions. I am currently in the process of converting a...
7
by: DB_2 | last post by:
Hello, I was trying to load a comma-separated text file to a DB2 table. I believe I have the syntax rigt for the LOAD command. My first question is, how do you actually run it? It is not a...
1
by: Paresh Mahajan | last post by:
Hi All, I need to call (run/execute) sample.sh file from the windows perl file. I know in linux it can be called as `sample.sh`; but that is not working in window XP. Here my Sample.sh is...
1
Colloid Snake
by: Colloid Snake | last post by:
Hey everyone. I'm currently attempting to band-aid an horrible use of a Cacti implementation (and I swear, this is only temporary! No, really! They told me it's in the budget for next year, and has...
0
by: .nLL | last post by:
Erorr is --------------------- Microsoft VBScript runtime error '800a0046' Permission denied /a.asp, line 3 -----------------------
1
by: looza | last post by:
Hi All, I have a bunch of shell script files that use a common shell script file that contains certain global variables that are declared and initialized or derived by some arithmatic. I have...
3
by: Max Vit | last post by:
I have come across a strange issue whilst trying to use a shell command call from Access and have spent some time trying to figure this out but can't find the cause as yet. The issue is: I need...
7
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.