Programming :: Calling A System Command In Perl?

May 20, 2010

I'm trying to call a system command in perl and am having an issue with it.

Here's an example of a command i'd like to call: Code: sed -i '4 c192.168.1.4 www.something.com' hosts this is the section in my perl script where I create the variable and call it: Code: $doit = `sed -i '$line c$ip $host hosts'`system($doit); The $line, $ip, and $host variables are working fine becasue I can replace that section with "prints" and they come out fine. I imagine the problem is where I am creating the $doit variable.

View 7 Replies


ADVERTISEMENT

Programming :: Calling Subroutine In Perl

Aug 19, 2010

What is the difference in perl between:

'function();'

and

'&function();'

with and without ampersand.

View 1 Replies View Related

Programming :: Perl About System Command / Fails If The Standard Shell Is Dash And Not Bash?

Jun 30, 2011

I am trying to fix a perl script, and I really suck at perl. But I think this problem will be easy for people who know it.

The problem is, I have an old setup script someone wrote many years ago. It fails if the standard shell is dash and not bash. The only way I've gotten it to work is to point /bin/sh to bash. I looked thru the script and it uses "system" many places, and I think that's the problem.

I searched for it and found this link:url

My plan is to include this function:

Code:
sub system_bash {
my @args = ( "bash", "-c", shift );
system(@args);
}
Then I could simply change all calls to system into system_bash and it should work?

The parameter to the system calls is usually some variable. What if the parameter is a list already? Do I need to test for it somehow, and if it's a list, prepend "bash" and "-c" to the list? How do I do that?

In the script there are lots of places like this:

my $error = system($cmd);
if ($error) {
die/warn "some error message";
}

Shouldn't there be a return in the system_bash function?

View 8 Replies View Related

Programming :: Calling Command From History Using Variable Like !$command?

Nov 19, 2008

suppose i store the history number of a command say :

1004 cat file

Then now i want to run it like : !1004 but by using a variable.

command=1004
!$command

i am getting errors like :

command=1004command

View 2 Replies View Related

Programming :: Calling System Calls In C Runtime (in The Run-time)?

Sep 23, 2010

I know there is a way to call winapi in runtime in windows. I want to ask how can I call a system call in gcc in runtime (when I don't know what it can be)? I don't mean syscall that I think is for calling only system calls and not library functions.

View 4 Replies View Related

Ubuntu :: Execute System Command With Perl?

Jun 13, 2011

i want to execute system command with perlm but it gives me error.

command is wmic client. here it is

#!/usr/bin/perl
open (EP, "/home/user/Templates/domainpc.log");
while (<EP>) {
chomp;

[Code]....

View 1 Replies View Related

Programming :: Assigning Output Of A Command To An Array In Perl?

Nov 25, 2010

I am trying to execute a Unix Command in perl and assigning its output to an array:

Code:
@File_List=exec("ls -1 /tmp");
but it is not working. I have tried the perl function system() also but its return code is

[code]...

View 10 Replies View Related

Programming :: Sed Bash Command - Not Print Backslash In Perl

Jul 11, 2010

This pretend to be a script for rename a lot of files automatically. So I put the list of files in an array named @lista. But, as you can see, at the end of the command I use a sed filter to print out a backslash for those files that have spaces in their names, so the path for those files could be rightly interpreted.

But there's no way I could print a backslash. It works well when I use the Perl's sed substitution s///, but I need every path in the array to be fixed.

I'd like to add that the bash command works perfectly well alone. I mean outside the Perl script.

This is de command line with the sed filter:

Code:

And this is what it brings:

Code:

View 12 Replies View Related

Programming :: Calling A Script From Another Script - Command Not Found

Mar 25, 2010

I'm trying to call a shell script from within another scipt, but returns with a `command not found` error msg.

script_name=$1
./$script_name &; exit 0

I think its something to no with the "./" bit. i also tried

"./"$script_name &; and
"./$script_name" &

no luck.

View 3 Replies View Related

Programming :: 32512 Error Code In Perl When Trying To Run Shell Command?

Nov 29, 2010

when I execute the command from the shell command line - it works and no error code.if I do the exact same command from a perl file - it fails with code 32512.the file is created from the same perl script that runs the command that fails. file permission is 0664.

Code:
#! /usr/local/pkg/perl-5.8.8/bin/perl
print "Content-type: text/html

[code]...

View 3 Replies View Related

Programming :: Calling "system()" Function From Cgi C Program?

Apr 3, 2011

when i call the "system()" function from my C program everything works well, but when i try to call it from a cgi C program it doesn't work. the server log tells me this is a permission error.i have chmod'ed 755 the cgi program but it still does not work.

View 5 Replies View Related

Programming :: Perl - Way To Encrypt Command-line Input When User Enter A Password ?

Nov 4, 2010

I need user to input a password through command line in Windows cmd prompt. Is there a way to encrypt the input (such as put it into ......) when user is typing ?

View 2 Replies View Related

Programming :: Find And Replace A String In A File Using Perl Command From Bash Script?

Feb 14, 2011

I wanted to find and replace a string from a perl file. I have written a script in bash which runs the following command.

perl -pi -e "s/$findstring/$replacestring/" testfile
where as $findstring = print F_WC_TMP"$line
";
and $replaceString = $line = join ' ', split ' ', $line; print F_WC_TMP"$line
";

But when I am running the above command, i think it is replacing the $findstring with the above mentioned string and hence it contains a $line, it is looking for the variable $line and not finding the exact string. I am confused about how to search for a string that contains $ in it and replace it with another $string.

View 5 Replies View Related

Programming :: Write A Perl Script Which Will Give An Interactive Session To A User To Execute Command On The Server

Feb 25, 2011

I am trying to write a perl script which will give an interactive session to a user to execute command on the server. I have written a small script to do this :

Code: !/usr/bin/perl -w
use strict;
use Net::SSH::Perl;
my $host = '192.168.1.1';
my $username = 'user';
my $login_passwd = 'test123';

[Code]...

View 2 Replies View Related

Programming :: System Command / 'mcc' Is Not A Recognised As An Internal Or External Command?

Apr 13, 2010

I am writing a perl script which uses the matlab compiler to compile a .m file.

I am using the system("mcc �m file.m"). I have matlab installed and both script and exe are in the same drive.But i get the following error .

'mcc' is not a recognised as an internal or external command ,operable in program or batch file.

View 5 Replies View Related

Programming :: Calling An Asm Function From C?

Jun 4, 2010

I have a question about calling an asm function from C....It doesn't work unless I create an asm variable to hold the value of the function in....Why?Here's the code that doesn't work...

asmfile.s - version one Code: .section .data
mydata: .ascii "this is the message!
.equ mylen, . - mydata

[code]...

View 2 Replies View Related

Programming :: Calling C Function In Php?

Feb 7, 2011

I am doing a web site program and what I need is to call a C program in the PHP cloud.Do u think it would be possible? The web site would get the user input from PHP UI and pass to the C program , the C program would process the function with the user input and output the a PHP page.

View 2 Replies View Related

Programming :: Calling C Ece From Java Source

Aug 13, 2010

I want to call c exe from java source code and i want to interact with the c program during it's execution, i am able to send the parameters to c program but i am not able to interact with it.

View 3 Replies View Related

Programming :: Tty Is Closed Without Calling Close(?)

Feb 17, 2011

I have found a weird behaviour on a linux application. A tty seems to get closed without calling close. The program is (very simplified) as follows:

Process 1:
configure_signals()
read_config_files()
create_threads()
wait(forever)

Thread 1:
fd=open(/dev/ttyXX)
usleep(a while)
config(fd)

I have spent quite a lot of time on this problem. It seems like the file is sometimes closed when reaching config(fd), but removing the usleep(a while) seems to remove the problem.

View 1 Replies View Related

Programming :: Calling Bash Script In Php?

Jul 17, 2010

I have a bash script that changes the iptables.Now i call this bash script in my php code.When this bash script is running the part of code that contains iptables instruction is not running because we need to be in superuser mode(root)

View 14 Replies View Related

Programming :: Calling Fortran 95 Code In C?

Apr 15, 2009

I'm trying to call some Fortran 95 code in C, but I'm having problems with integers not having the same value in C as in Fortran, and changing values upon each run of the program. I think it has to do with the integer type, but I don't know how to fix it. I'm running Gentoo x86. Here are the files I've got:

foo.c:

Code:

#include <stdio.h>
extern int qux_();
main() {

[code]....

View 2 Replies View Related

Programming :: Use The Sockaddr_in Like Before Calling Bind()

Jul 30, 2011

i use the sockaddr_in like this before calling bind(), it works good.

Code:
sockaddr_in serveraddr;
serveraddr.sin_port=htons(5000);
serveraddr.sin_addr.s_addr=htonl(INADDR_ANY);
serveraddr.sin_family=AF_INET;

[Code]....

View 2 Replies View Related

Programming :: Calling Routines In Fortran Modules From C++?

Jan 21, 2011

I want to call a subroutine in Fortran 90 from a c++ code. I can do it, when the fortran code have no module. But i need to call the subroutine in a fortran code that have an module. I have a simple program that shows my problem. The Fortran code is:

Code: !add2.f90
Module add2
Implicit none
Contains

[code]....

collect2: ld returned 1 exit status I Dont know where is the problem. Maybe it is in the call of the function. I found that the syntax have this form: extern void __namemodule__NMOD_namesubrutine(arg)

View 6 Replies View Related

Programming :: C++ - Calling Functions From Other Files And Headers?

Apr 11, 2011

I feel like there should be a cleaner way of doing this. I have one file, for example "a.cpp", calling a function from another file, "b.cpp". Currently I have it set up so that header for "b", "b.h", has the declaration of its functions. And then I'm just including "b.h" in "a.cpp". Do I have to include the "b" header file in "a" to be able to call a function from "b"? Or is there a better way I could be doing this? Like doing something different at compile?

View 7 Replies View Related

Programming :: Calling Gcc From Executable File / (makefile)

Oct 4, 2010

I am trying to use a software package written in ANSI C. It has a makefile which has to be executed first.

As soon as I execute it I get messages like: line i: command not found.

Commands for which I am getting errors :

CC = /usr/bin/gcc
GCCFLAGS = -c -Wall
ROOTDIR = .

My gcc compiler is located in the above directory only. In ROOTDIR also I tried giving the path in which all the required files & folders are present but still I get the command not found error in all the lines.

View 7 Replies View Related

Programming :: Calling Kernel Functions From Userspace?

Feb 5, 2010

I'm trying to call some kernel functions from userspace, but I'm not sure if I'm doing it right. The functions control a pulse width modulator on an embedded platform. To pick one at random, the function:

Code:
struct pwm_device *pwm_request(int pwm_id, const char *label);
is defined in linux/pwm.h, and the implementation uses the macro EXPORT_SYMBOL(pwm_request), so I should be able to call this from user-space... right?

Anyway, I've got linux/pwm.h to #include in my source so the compiler knows what it's doing, but what do I link against? The only place in by kernel build tree where I can see a symbol pwm_request defined is in object files like vmlinux.o, built-in.o in the directory, etc. which I don't think I should be linking against.

View 2 Replies View Related

Programming :: Calling Multiple Files In FORTRAN90

Oct 29, 2010

I have written FORTRAN code to calculate density profile. This code will open two files ( topology and x,y,z trajectory). The trajectory file contains XYZ data coordinates for multiple frames (about 20 or 100 frames for instance). One frame contains 20736 data.

Previously this code was written to open ONLY one input XYZ data file and do the calculation and would dump the results in separate file and it was running without problem. Recently my data file get bigger in size, so I decided to break the single XYZ data file into few small parts.

Now I have modified the code so that it calls the parts of the XYZ data files ( eg: maltoTHERMO_10Frames.traj, maltoTHERMO_20Frames.traj,... and so on) and do the calculation and dump the results in the same result output file. I have tested this code just with openning the XYZ coordinates and printing into another file to see wheather it collecting the data sequently and it was working fine.

This code supposedly read the x coordinate data and calculate distance and put a count accoding the criteria in the approperiate bins. But when I let the code to do the calculation it stop and shows error. (I have indicated as !** in the code). If I enable this line, it shows error but if I disable this line, than the code do collect only the XYZ coordinates.

The code is as below:

Code:

module all_parameter
integer,parameter :: MAXATOM=20736!CHANGE
integer,parameter :: midwater=1500
integer,parameter :: TOTALFRAMES=20

[Code]....

View 8 Replies View Related

Programming :: Calling Script From Php Page Is Not Working?

Mar 2, 2011

I have typed the following code:

Code:
<html>
<form enctype="multipart/form-data" action="upload.php" method="POST">

[code]...

View 3 Replies View Related

Programming :: Calling Sizeof From Custom Function?

Oct 17, 2010

lets look at code in C

Code:
#include <stdio.h>
#include <stdlib.h>

[code]...

View 3 Replies View Related

Programming :: Play With Calling Text Files In C

May 5, 2010

I am trying to play with calling text files in C. What I have is a text file with 4 columns of numbers I need to average 2 of them. I have started and hit a wall. I have the following so far:

[Code]....

I still need to figure out how to read the data in. I have been reading on this for a few hours and its not clicking. How does the program know which columns with names to call. the data is organized: ID, Day, Speed, Temp.

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved