Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: A few random questions.

by BrowserUk (Patriarch)
on Dec 09, 2003 at 22:09 UTC ( #313576=note: print w/replies, xml ) Need Help??

in reply to A few random questions.

For your first question the simplest way is

perl -e"system 'start cmd';"

Depending upon what you want to do with the new command shell, then you may want to follow the "cmd" part with /c or /k and then the command you want to run.

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail

Replies are listed 'Best First'.
Re: Re: A few random questions.
by Elijah (Hermit) on Dec 09, 2003 at 23:21 UTC
    That works great but I cannot seem to feed the command I want to the newly spawned command prompt. What would the syntax be for that?

    system("perl -e\"system 'start cmd';\" /c perl \"$filename\"");
    I have tried the preceeding code and a few other variations but have been unsuccesfull.

      Based on your example, you want to run another perl script from within your perl program, and have it present its output in a separate cli window, then this maybe what you are looking for.

      my $filename = 'some perl script (potentially with spaces).pl'; system qq[ start cmd /k perl "$filename" ];

      Using qq// for the outer set of quotes removes the need to escape the inner ones needed around the filename whilst still allowing $filename to be interpolated. See Quote-like operators for more info.

      Using /k will ensure that the window remains and the script output is visible after the command has ended.

      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "Think for yourself!" - Abigail

        Worked great, thank you!
      All you need to do to run a command with options is to join them in one long string. eg.
      my $process = join (" ",$execution_path, $options); system ($process);
      However, this won't work with the command prompt as you can't pass further instructions to a command line without a special option switch (/K). I don't really understand why you need to open another DOS Box to run something, as the system() command will wait for the process to terminate before continuing. Nevertheless, with the /K option, your script should open a new DOS box to run the script.
      my $execution_path = "cmd.exe"; my $options = "/K C:\\Perl\\Perl.exe"; my $process = join (" ",$execution_path, $options); system ($process);

      However, if you can't get what you want out of system(), then check out Win32::Process, this has numerous facilities for creating and manipulating processes, you can even suspend or kill processes at a PID level. As for the TK question, I'm afriad that I haven't even started looking at TK yet.

      Seems BrowserUK got there before me on the /K thing though....

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://313576]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2023-12-01 10:15 GMT
Find Nodes?
    Voting Booth?

    No recent polls found