Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Fork Opens CMD Not the Process

by anshumangoyal (Scribe)
on Jul 13, 2012 at 20:47 UTC ( #981721=perlquestion: print w/ replies, xml ) Need Help??
anshumangoyal has asked for the wisdom of the Perl Monks concerning the following question:

I have a windows EXE, which gives me some data. When I run this using my code below, two processes are created: One is cmd.exe and other is .exe which I am running. the $pid has PID of cmd.exe, Is there any way that I can have $pid the PID of .exe I am running. Here is my code:
my $Command = abc.exe my $pid = open ($fileHandler, '-|', "$Command 2>&1"); if ( ! defined $pid) { die "Cannot Open Command\n"; }

Comment on Fork Opens CMD Not the Process
Download Code
Re: Fork Opens CMD Not the Process
by tobyink (Abbot) on Jul 13, 2012 at 21:09 UTC

    That code will not run at all. (Missing a semicolon after abc.exe.)

    If you want help, please post actual code.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
Re: Fork Opens CMD Not the Process
by zentara (Archbishop) on Jul 13, 2012 at 21:11 UTC
Re: Fork Opens CMD Not the Process
by ig (Vicar) on Jul 14, 2012 at 00:22 UTC

    I ran

    my $cmd = 'C:/program files (x86)/vim/vim72/gvim.exe'; my $pid = system 1, "$cmd"; print "pid = $pid\n";

    on Windows 7 64bit and the pid printed was that of gvim.exe.

Re: Fork Opens CMD Not the Process
by BrowserUk (Pope) on Jul 14, 2012 at 00:36 UTC
    Is there any way that I can have $pid the PID of .exe I am running.

    No. Not whilst you need to do shell redirection: 2>&1.

    In order to get shell redirection, you need a shell.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

      In order to get shell redirection, you need a shell.

      Damn that logic, full speed ahead!

      SCNR

      "I know what i'm doing. Look, what could possibly go wrong? All i have to press this button here and ArghhhhhaaAaAAAaaagraaaAAaa!!!"
Re: Fork Opens CMD Not the Process
by zentara (Archbishop) on Jul 14, 2012 at 10:42 UTC
Re: Fork Opens CMD Not the Process
by Anonymous Monk on Jul 14, 2012 at 12:07 UTC
    my $Command = abc.exe

    That isn't likely to do what you think without quotes (not to mention the semicolon, again).

    [jth@reina ~]$ perl -E 'my $Command = abc.exe; say $Command' abcexe

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://981721]
Approved by tobyink
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (10)
As of 2014-09-19 09:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (133 votes), past polls