Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to write a simple script to 1) open a new CMD window 2) navigate to a location 3) execute a .exe 3) run commands in new state (from .exe). The purpose of the exe is to open a com into another program.

#!/bin/perl use strict; use warnings; system ('start cmd /k cd C:/some location/gateway.exe uname@jupiter.ju +piter &&COM open_job,job=232');

Replies are listed 'Best First'.
Re: Run executable and follow on commands from CMD line
by cosmicperl (Chaplain) on Oct 22, 2018 at 14:40 UTC
    Not something I've tried before. But there might be a way by using open, much the same way you would when piping things to sendmail:
    open(MAIL, "|/usr/sbin/sendmail -t"); print MAIL "To: $to\n"; print MAIL "From: $from\n"; print MAIL "Subject: $subject\n\n"; print MAIL $message; close(MAIL);
    Otherwise, as you are on windows, maybe part of what you need can be achieved with a .bat?

      Wow!! Thank you so much! I hadn't tried that approach yet. I spent about 6 hours trying all kinds of stuff! But it worked perfectly! Here's the code I just used.

      open(Gateway, "|C:/some location/gateway uname\@jupiter.jupiter"); print Gateway "COM open_job,job=232\n";