473,591 Members | 2,871 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling programs from perl without temp files

Hello,

In a Perl script, I run a program, Program.pl, by using:

@output = `cat $file_name | Program.pl`;

However I want to run this program when the contents of the file named
$file_name are stored in a string variable called $file_contents, as I
don't have permission to store them in a file. So I want to capture
something like:

@output = `cat $file_contents | Program.pl`;

Does anyone know how this can be done?

Many thanks for your help,

Richard
Jul 19 '05 #1
3 4555
R Evans wrote:
Hello,

In a Perl script, I run a program, Program.pl, by using:

@output = `cat $file_name | Program.pl`;
Useless use of cat. Why not
Program.pl < $file_name
However I want to run this program when the contents of the file named
$file_name are stored in a string variable called $file_contents, as I
don't have permission to store them in a file. So I want to capture
something like:

@output = `cat $file_contents | Program.pl`;

Does anyone know how this can be done?


You mean something like

@output = `echo $file_contents | Program.pl`;
jue
Jul 19 '05 #2
In article <w0HZc.502$H26. 135@trnddc07>, Jürgen Exner
<ju******@hotma il.com> wrote:
R Evans wrote:
Hello,

In a Perl script, I run a program, Program.pl, by using:

@output = `cat $file_name | Program.pl`;


Useless use of cat. Why not
Program.pl < $file_name
However I want to run this program when the contents of the file named
$file_name are stored in a string variable called $file_contents, as I
don't have permission to store them in a file. So I want to capture
something like:

@output = `cat $file_contents | Program.pl`;

Does anyone know how this can be done?


You mean something like

@output = `echo $file_contents | Program.pl`;


I think the poster means that $file_contents contains the _contents_ of
the file, not the name (i.e. { local $/; $file_contents = <FILE> } ).
In that case, you can do something like (untested):

open(EXE,'|Prog ram.pl') or die $!;
print EXE $file_contents;

See 'perldoc -f open' and 'perldoc perlipc'. If you also want to
capture the output of the program, then you need to see IPC::Open2 and
IPC::Open3, which may not be supported on all platforms.
Jul 19 '05 #3
Hi,

Thanks for pointing me to Open2. I got what I wanted using:

----------------------------------
use IPC::Open2;
$pid = open2(\*RDRFH, \*WTRFH, 'perl Program.pl');
print WTRFH $file_contents;
close(WTRFH);
@output=<RDRFH> ;
----------------------------------

All the best,

Richard
Jim Gibson <jg*****@mail.a rc.nasa.gov> wrote in message news:<020920041 244523982%jg*** **@mail.arc.nas a.gov>...
In article <w0HZc.502$H26. 135@trnddc07>, Jürgen Exner
<ju******@hotma il.com> wrote:
R Evans wrote:
Hello,

In a Perl script, I run a program, Program.pl, by using:

@output = `cat $file_name | Program.pl`;


Useless use of cat. Why not
Program.pl < $file_name
However I want to run this program when the contents of the file named
$file_name are stored in a string variable called $file_contents, as I
don't have permission to store them in a file. So I want to capture
something like:

@output = `cat $file_contents | Program.pl`;

Does anyone know how this can be done?


You mean something like

@output = `echo $file_contents | Program.pl`;


I think the poster means that $file_contents contains the _contents_ of
the file, not the name (i.e. { local $/; $file_contents = <FILE> } ).
In that case, you can do something like (untested):

open(EXE,'|Prog ram.pl') or die $!;
print EXE $file_contents;

See 'perldoc -f open' and 'perldoc perlipc'. If you also want to
capture the output of the program, then you need to see IPC::Open2 and
IPC::Open3, which may not be supported on all platforms.

Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4835
by: Ulvaeus | last post by:
Is there any way I can create a program that deletes Temporary Internet Files. I want to create a program that will run in Windows 2000/XP which can remove Internet History and Temp files but don't know how to set the File1.path so that it can show the temporary internet files and history. Thanks Ulvaeus
0
1546
by: Joe Ray | last post by:
Can anyone suggest a technique for calling a Perl Script within a JSP page. Thanx Raymis
1
2945
by: Reader | last post by:
Hello, I would like to know if there is a way to cache the xmlserializer-generated temp files and have the program reuse these cached files upon new application instances. For example, application 1 launches. The first time it uses the serializable classes the XmlSerializer will create a source file on the fly and compile it and use this file to serilize and deserilize the XML. When Application 1 is launched in a new instance say...
3
7274
by: Harsh Vardhan Singh | last post by:
hi, i am trying to create a temporary file associated with a particular process. For instance, i have a windows application which will create a temp file as soon as it this program is executed. Now i want this temp file to be destroyed if this application is closed / crashes. Is this possible? Please help. Thanks in advance, Harsh
2
3112
by: David Hearn | last post by:
I am using some temporary text files and xml files to store some data in during a users session. When their session ends (they leave the site or their session times out) I need to delete these files. What is the best way to do this? Thanks in advance!
4
1454
by: Satish | last post by:
what is the difference between persistet DLL(ASP.NET Temp Files) and one which is IIS/Webapplication/ BIN Folder. can anyone tell what exactly happens for the first request for the above senario. regards Satish
2
11458
by: Matt | last post by:
Get this wierd compiler error on my production machine after publishing the site in VS 2005, have no idea what it is..removed the temp files and it just remakes them. Compiler Error Message: CS0433: The type '_Default' exists in both 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50215\Temporary ASP.NET Files\testpopoff\90b00d8e\4772ca2f\assembly\dl3\a9d383b3\5a6f804f_a7ebc501\App_Web_5n48zyrm.DLL' and...
2
1799
by: boolieann13 | last post by:
Hi, Are files generated to local temp files necessary for your computer? I keep getting error messages such as not found, after I deleted something from wild tangent which attached itself to my C drive. One of the five messages I continue to get every time I reboot is: C:\Docume~\Owner\Locals~1\Temp\WER2F.Tmp.dir00\navapw32.exe.mdmp. Any feedback would be greatly appreciated! Thanks!!!
0
1051
by: Lawrence Krubner | last post by:
Imagine I have a site where users can upload files. Now imagine we are enfocing a 100 meg limit on each account. The user uploads a file, the code checks to see if they are already over their limit. If not, the PHP upload code precedes as normal and I use move_uploaded_file() to copy the temp file to its permanent home. But if the user is over their limit, then I do not use move_uploaded_file(). I simply notify the user that they are over...
0
7870
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8236
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8362
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7992
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5400
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3891
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1465
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1199
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.