Running a CMD.exe from PowerShell with arguments

Hello guys, I am working with a driver backup program that I need to automate. I am using Power shell to run a few other tasks, like check the OS version and create a folder based on the system type for drivers. We deploy many different devices and needed
a way to automate. That is neither here nor there. Here is what I am trying to run, but the CMD, will not seem to pick up the arguments. If I run from the CMD prompt, it will run as expected, but when I lick it off with Power shell, I get a few errors. 
Here is what I have:
$command = @'
cmd.exe /C C:\DriverBU\DrvBK.exe MODE="BACKUP" BKPATH="C:\TempDrivers" BKDESC="Drivers" BKFILE="Backup %NOW%  %COMPUTERNAME%.bki" BKPATHFTM="%COMPUTERNAME%" BKDEVFMT="%DEVNAME%" BKDATEFMT=""
OPT="HW"
Invoke-Expression -Command:$command
This will open the program, however, will not run the arguments.
Thoughts?
Thank you!
Paul
Duramaxster

Hello guys, I am working with a driver backup program that I need to automate. I am using Power shell to run a few other tasks, like check the OS version and create a folder based on the system type for drivers. We deploy many different devices and needed
a way to automate. That is neither here nor there. Here is what I am trying to run, but the CMD, will not seem to pick up the arguments. If I run from the CMD prompt, it will run as expected, but when I lick it off with Power shell, I get a few errors. 
Here is what I have:
$command = @'
cmd.exe /C C:\DriverBU\DrvBK.exe MODE="BACKUP" BKPATH="C:\TempDrivers" BKDESC="Drivers" BKFILE="Backup %NOW%  %COMPUTERNAME%.bki" BKPATHFTM="%COMPUTERNAME%" BKDEVFMT="%DEVNAME%" BKDATEFMT="" OPT="HW"
Invoke-Expression -Command:$command
This will open the program, however, will not run the arguments.
Thoughts?
Thank you!
Paul
Duramaxster
Part of your problem is that you cannot use @''@  (a here string) to specify a command because it retains the line breaks.
¯\_(ツ)_/¯

Similar Messages

  • Running a captivate .EXE from a Intranet site

    I am currently trying to run a Captivate .EXE from our
    internal intranet site.
    I have created a 'front end' captivate project which will act
    as the 'launch site'. Basically the buttons on the project should
    launch the .EXE files held on our network, but for some reason it
    doesnt seem to work. I have checked and double checked the file
    paths and have tried it on both a restricted network and an open
    one, to rule out access issue but this doesnt seem to make a
    difference.
    Can anyone help or have any ideas??

    Hey there Collywobble1
    I am not too sure on the intranet setup, but, in essence the
    2 output formats for Captivate are intended for 2 seperate
    requirements as I understand it.
    SWF outputs are for network and internet based access and EXE
    outputs are for standalone files on a user computer, CD etc. So it
    seems as though you might have to convert your files to SWF and try
    again.
    If I am wrong, then could some other super genius please
    assist (Rick, Larry, Jbradley88 et al)
    Cheers
    Andrew

  • Starting IExporer.exe from java with J9 in an IPAQ

    Hi all,
    I'm trying to run IExplorer.exe from a java program in a IPAQ with j9 cvm.
    I did try it in Windows 2000 and it works fine but when running it in the IPAQ with Windows CE it throws an exception.
    Looks like the Exception is thrown because it can not find the file, but I think I'm writing the correct path and file name.
    Here is the code and the exception. Can any one try it and tell me what Am I doing wrong.
    Thanks a lot.
    String s = "\\Windows\\iexplore.exe";
    //String s = "\"C:\\Program Files\\Internet Explorer\\IEXPLORExx.EXE\"";
    try
    System.out.println("s: " + s);
    Runtime runtime = Runtime.getRuntime();
    Process p = runtime.exec(s);
    catch(IOException ioEx)
    ioEx.printStackTrace();
    java.io.IOException: Unable to start program
    Stack trace:
    com/ibm/oti/lang/SystemProcess.create([Ljava/lang/String;[Ljava/lang/String;L
    java/io/File;)Ljava/lang/Process;
    java/lang/Runtime.exec([Ljava/lang/String;[Ljava/lang/String;Ljava/io/File;)L
    java/lang/Process;
    java/lang/Runtime.exec(Ljava/lang/String;[Ljava/lang/String;Ljava/io/File;)Lj
    ava/lang/Process;
    java/lang/Runtime.exec(Ljava/lang/String;[Ljava/lang/String;)Ljava/lang/Proce
    ss;
    java/lang/Runtime.exec(Ljava/lang/String;)Ljava/lang/Process;
    com/gestorPosicion/inicio/InicioCliente.main([Ljava/lang/String;)V                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    The problem is that on PocketPC you cannot redirect input or output and the exec() call will not work as expected so it instead throws the exception to indicate this doesn't work on PocketPC.

  • Creating .exe from .swf with Adobe Flash Player 13

    Hi,
    I usually export to .exe from .swf files using the Adobe Flash Player.
    I've update flash to the 2014 version and now this "create projector" remain in gray color, so, unavailable.
    Do you now if there's a solution?
    Many thanks

    Lols, so easy!
    Many thanks!

  • Error when running captive runtime .exe from root directory of drive.

    Platform: Windows
    Specifics: Captive runtime desktop app using an ANE.
    Problem:  I am distributing the app on a flash drive. Ideally,the .exe will be on the root of the drive, so the user will not need to enter a subdirectory. I'm mostly concerned about users moving the software and getting frustrated by this error.
    The error is "Adobe Air: The installation of this application is damaged. Try re-installing or contacting the publisher for assistance."
    Here's an example. Importantly, this error only occurs when an ANE is included. I tried a few different ANE files created by others, and simply adding them to the project produces the error. I don't even need to use the ANE anywhere in my code.
    https://www.dropbox.com/s/epfj0138pfbmu49/soExample.7z
    This is a simple application with a few blank buttons. Try extracting in a subdirectory somewhere, and then moving to the root of a flash drive or any other drive. However, I don't recommend running code from strangers on the top directory of your C:\ drive.
    Additionally, I installed Apache Flex 4.12 but the error persists. The text simply changed to "Initial content could not be loaded for this application. Try re-installing or contacting the publisher for assistance."
    https://www.dropbox.com/s/epfj0138pfbmu49/soExample.7z

    I did some more testing. Same issue occurs if I create a captive runtime app from Flash Pro. It also happens when I use the Adobe Air installer, but install to the root directory.
    Can anyone think of a workaround?

  • Run a cmd command in LabVIEW with parameters

    I have an executable program, for example myprogram.exe, located in "C:\Documents and Settings\myname\myprogram.exe" (I use windows xp 32 bit)
    When I run the program (by running cmd and type "myprogram.exe > to_text.txt" on the command line), the program will print out the result to that text file.
    But when I try to run the whole thing on LabVIEW, I can't manage to do so. LabVIEW only supports using the "Run Command" of Windows, not the cmd. (using the SystemExec vi)
    So how can I run "myprogram.txt > to_text.txt" on LabVIEW as I run it in cmd? Moreover, how can I send the break event (by pressing Ctrl+C in the cmd) by LabVIEW to stop the program?
    With my appreciations!

    I made this a while ago and haven't tested it too much but it should do what you want.  Provide the application path, then the switches in the array.  It does work with built in commands like dir and copy.
    Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
    If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.
    Attachments:
    Execute Command Line With Switches.vi ‏24 KB

  • Running Hardware Test or Running Mac OS X from DVD with an older iMac

    I have a 4 year old iMac which is running Snow Leopard 10.6.2 and using a wired aluminum keyboard along with a Magic Mouse. I recently had some files corrupted so that when I booted up, the dock would not load and could not run any programs. It appeared to me that Finder wasn't working properly.
    In any event, I tried to run the Apple Hardware Test from the Snow Leopard DVD by starting the computer and pressing the D key but the computer would not boot off the DVD and continued booting off the hard drive.
    I also tried starting the computer with the C key to try and do a reinstall of OS X, again with same result.
    I ended up bringing the computer to Genius Bar at local Apple Store. The tech guy plugged an older styled white plastic keyboard and the computer recognized the D and C keys during start up. He then did a recovery of OS with no problems.
    He downloaded a firmware update for me to install when I got home. When I tried to install the update, updater said firmware update is not needed.
    At the moment, I'm in the same position as before. The computer runs fine but I still can not boot off the DVD because the aluminum keyboard's keys are recognized at startup.
    Any ideas on firmware update to rectify this? Don't have the older plastic keyboard and seems silly to have an old one on hand in case computer acts up.

    I tried resetting the PRAM but since keyboard keys are not recognized on booting up, holding the CONTROL, COMMAND, P & R keys didn't work. I noticed that on older Power PC Macs that holding Power On button continuously while starting up would force computer into Open Firmware so PRAM could be reset. This didn't work for me.
    I also reset the SMC.
    When I look in Utilities, I see that Aluminum Keyboard Firmware Update 1.0 is installed last modified on Oct. 8, 2009. I've had the keyboard much longer than that so not sure what that means. When I clicked it, it said firmware is up to date.
    In any event, is there any way to force a firmware update even if my computer says the firmware is up to date? Thanks

  • Running an ouside exe from java application

    Hi
    My application should display an help button that will open a pdf file in a browser or in acrobat reader.
    I would like to know how to start an outside applicatioon from my application.
    thanks,
    Liat

    My os is win 2000 professional
    the code:
    public static void main(String[] args) throws Exception {
    Process p = Runtime.getRuntime().exec("c:\\temp\\1.pdf");
    p.waitFor();
    System.out.println("Done.");
    and this is the exception:
    com.bitband.maestro.gui.temp.Demo1
    java.io.IOException: CreateProcess: c:\temp\1.pdf error=193
         at java.lang.Win32Process.create(Native Method)
         at java.lang.Win32Process.<init>(Win32Process.java:66)
         at java.lang.Runtime.execInternal(Native Method)
         at java.lang.Runtime.exec(Runtime.java:566)
         at java.lang.Runtime.exec(Runtime.java:428)
         at java.lang.Runtime.exec(Runtime.java:364)
         at java.lang.Runtime.exec(Runtime.java:326)
         at com.bitband.maestro.gui.temp.Demo1.main(Demo1.java:100)
    Exception in thread "main" Process terminated with exit code 1

  • Start an application from console with arguments

    Why do I get an ArrayIndexOutOfBoundsException when I try to start the application with
    > java Application 12345
    public static void main(String[] args)
              String host = args[0];
              String port = args[1];
              if(port.length() == 0)          
                   port = "500";
              System.out.println(host+"\n"+port);
         }

    I have modified the main method and here it is. My problem is described below the code.
    public static void main(String[] args) throws IOException
         String host;
         int port;
              if(args.length == 0)
                   host = "address.to.server";
                   port = 1000;
              else if(args.length == 1)
                   host = args[0];
                   port = 1000;
              else
                   host = args[0];
                   try
                        port = Integer.parseInt(args[1]);
                   catch (NumberFormatException ioe){ port = 1000; }
              try
                   new Client(host, port);
              catch (ConnectException ce){ System.out.println(ce.getMessage()+" "+host+" "+port); }
              catch (NullPointerException npe){ System.out.println(npe.getMessage()+" "+host+" "+port); }
    }If I try to start the program through
    > java Clientthe connection is set up to host = "address.to.server";      port = 1000; and the program works.
    If I try to start the program through
    > java Client localhostI get Connection refused: connect localhost 1000
    If I try to start the proram through
    > java Client localhost 1000I get Connection refused: connect localhost 1000
    If I connect to a host that doesn´t exist, like
    > java Client localho 1000I get null localho 1000
    I have no Idea what´s wrong.
    Please, help!

  • How to run .cmd file from a Powershell script

    Hi,
    I would like to know how I run commands from a powershell script? how to use the invoke-command?
    This powershell script doesnt work for me
    Invoke-Command C:\setup.cmd -ArgumentList install-setupforced

    To run a batch file from powershell, just type its name with arguments. I'd recommend explicitly including the .CMD file type and, if it is located in the current folder, powershell rules require you to explicitly say so, i.e.:
       ./mybatch.cmd inputfile.txt outputfile.txt
    To run a single cmd.exe command, just prefix it with cmd.exe /c as Mike says:
        cmd.exe /c color 48
    to run a series of "&"- separated cmd.exe commands you need to enclose the complete command string in double quotes:
        cmd.exe /c "color 37 & dir"
    Beyond that it can get complicated due to various characters that are special to powershell and those special to cmd.exe. If you need to run a series of cmd.exe commands, your best short term bet is to put them in a batch file. The best long-term bet is
    to move more completely to the powershell way of doing things...
    Al Dunbar -- remember to 'mark or propose as answer' or 'vote as helpful' as appropriate.

  • Unable to run cmd.exe in hosted web application?

    Hi
    I have to execute a cmd.exe in web application to merge a file.My code work fine on my dev environment. But on hosting the
    application on server unable to run the cmd.exe . Below is the code.
     ProcessStartInfo processStartInfo = new ProcessStartInfo("cmd.exe");
                        processStartInfo.RedirectStandardInput = true;
                        processStartInfo.RedirectStandardOutput = true;
                        processStartInfo.UseShellExecute = false;
                        Process process = Process.Start(processStartInfo);
                        if (process != null)
                            process.StandardInput.WriteLine("c:");
                            process.StandardInput.WriteLine("xcopy " + srcfilename + " " + destfilename + "
    /a /m /d /s /e /v");
                            // process.StandardInput.WriteLine("a");
                            process.StandardInput.Close(); // line added to stop process from hanging on ReadToEnd()
                            string outputString = process.StandardOutput.ReadToEnd();
                            process.Close();
                            // process.Kill();                   
    Pawan

    What is the hosting you are using on azure? Hosted your application as Azure web site or cloud service?
    If it is a azure cloud service - you will either need to define the start up tasks to do the same or need to run your azure roles in elevated context.
    Read more - https://msdn.microsoft.com/en-us/library/azure/gg456327.aspx
    https://msdn.microsoft.com/en-us/library/gg557553.aspx#Runtime
    Bhushan | Blog |
    LinkedIn | Twitter

  • Runtime.exec and cmd.exe

    Just a quick one here, I think. I'm working on a little tool to merge changes into a document and then copy it over a communications port, and everything seems to be checking out except for that last step. Rather than worrying about streams and whatnot, I'm saving the file to the hard drive; from here, my plan has been to open the DOS prompt and take advantage of its "copy (filename) (port)" command to transfer the file. So in the end, the key line of Java should be something like
    Runtime.getRuntime().exec("cmd.exe copy \"" + fileName + "\" LPT1");My issue here is that the command prompt doesn't seem to want to open using Runtime.exec(). It seems like cmd.exe should do the job -- tossing that into the run menu certainly opens the prompt -- and even just to be sure, I've tried using C:\WINDOWS\system32\cmd.exe explicitly, and both that at cmd.exe without any additional arguments. Strangely, though, the prompt isn't opening, and I'm not getting an I/O error out of it as if I was sending in a bogus command.
    So what am I doing wrong here? What do I have to do to open the DOS prompt?

    As I mentioned, I did try providing the full path to cmd.exe, to no effect.
    Curiously, though, changing "cmd.exe" into "cmd.exe /k" or "cmd.exe /c" both cuased the command to run correctly. Contrary to what they're supposed to do, though, both of them result in the immediate termination of the DOS prompt, even though /k is supposed to cause the window to persist. Any ideas as far as that one goes?

  • Weblogic Server 7.0 - can't find cmd.exe

    Hi
    I am having a simular problem I have succefully installed web logic server 7.0 and created a domain "dlidomain". When I am trying to start->Programs-> " WebLobic Platform 7.0 -> User Projects --> dlidomain" its searching for "cmd.exe" which is not found in windows98. Your answer below was to rename cmd to bat. What files are you referring to? Is this still the soloution. Please let me know as soon as possible.
    Darryl
    renamed .cmd to .bat and see if it works or not.
    krishna ramineni wrote:
    hi
    i installed weblogicserver 7.0 on windows 98.and when iam trying to run
    setExamplesEnv.cmd file from dos prompt it says bad command or file name.and
    when iam trying to start->Programs-> "Launch Examples Server" its
    searching for "cmd.exe" which is not found in windows98.please let me know
    the solution for this asap

    What leads you to believe WLS is supported on Windows 98?
    Wayne
    Darryl wrote:
    Hi
    I am having a simular problem I have succefully installed web logic server 7.0 and created a domain "dlidomain". When I am trying to start->Programs-> " WebLobic Platform 7.0 -> User Projects --> dlidomain" its searching for "cmd.exe" which is not found in windows98. Your answer below was to rename cmd to bat. What files are you referring to? Is this still the soloution. Please let me know as soon as possible.
    Darryl
    renamed .cmd to .bat and see if it works or not.
    krishna ramineni wrote:
    hi
    i installed weblogicserver 7.0 on windows 98.and when iam trying to run
    setExamplesEnv.cmd file from dos prompt it says bad command or file name.and
    when iam trying to start->Programs-> "Launch Examples Server" its
    searching for "cmd.exe" which is not found in windows98.please let me know
    the solution for this asap

  • Controlling "CMD.EXE" via Process - Never ends?

    I'm trying to write a Java program that parses a text file & executes various command promt commands (I'm trying to keep it platform independant, because I know Lin/Un/nix users who would find this userful as well). I found a small tutorial on the web which gave an example of:
    Process p = Runtime.getRuntime().exec("<YOUR COMMAND HERE>");
    BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
    BufferedWriter stdOutput = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
    BufferedReader stdErr = new BufferedReader(new InputStreamReader(p.getInputStream()));
    Now; I have inserted "cmd.exe" for <YOUR COMMAND HERE>. If I write a command out to stdOutput, the first command executes, but not subsequent ones. Small segment looks like:
    while (line != null) {
    stdOutput.write("mkdir \"" + new_folder + "\"\n");
    stdOutput.flush();
    line = file_reader.readLine();
    This is an abridged version of my ode, but thats the problem. I get the first folder created, the process never terminates and I've tried emptying out the stdInput & stdErr bufferes, but it still won't execute subsequent commands issued to stdOutput.
    Can someone help me? I'd rather not write this all to a .BAT/.sh file :(

    I am quite perplexed now! I have just tried the following code on my PC, and have ended up with the most annoying two folders under my C:\ drive!
    import java.io.*;
    public class Cmd {
        public static void main(String[] args) {
            try {
                Process p = Runtime.getRuntime().exec("cmd.exe");
                BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
                BufferedWriter stdOutput = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
                BufferedReader stdErr = new BufferedReader(new InputStreamReader(p.getInputStream()));
    //            System.out.println(stdInput.readLine());
    //            System.out.println(stdInput.readLine());
    //            System.out.println(stdInput.readLine());
                stdOutput.write("mkdir \"c:\\folder1\"\n");
                stdOutput.flush();
    //            System.out.println(stdInput.readLine());
                stdOutput.write("mkdir \"c:\\folder2\"\n");
                stdOutput.flush();
    //            System.out.println(stdInput.readLine());
            } catch (IOException e) {
                e.printStackTrace();
    Perlexion over! Since you had your code in a loop I tried the same. I saw that in a loop creating 10 folders, the code created only two. See below the code that fixed this problem:
    import java.io.*;
    public class Cmd {
        public static void main(String[] args) {
            try {
                Process p = Runtime.getRuntime().exec("cmd.exe");
                BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
                BufferedWriter stdOutput = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
                BufferedReader stdErr = new BufferedReader(new InputStreamReader(p.getInputStream()));
                System.out.println(stdInput.readLine());
                System.out.println(stdInput.readLine());
                System.out.println(stdInput.readLine());
                stdOutput.write("mkdir \"c:\\folder1\"\n");
                stdOutput.flush();
                System.out.println(stdInput.readLine());
                stdOutput.write("mkdir \"c:\\folder2\"\n");
                stdOutput.flush();
                System.out.println(stdInput.readLine());
            } catch (IOException e) {
                e.printStackTrace();
    }Commenting out different combinations of System.outs gives different results.
    In summary: it is important that you match the correct number of output lines from the CMD.EXE output stream with readLines.
    I didn't like how the wording came out, but you get the gist.
    HTH,
    Manuel Amago.

  • Running an executable (.exe)

    Hi
    How can i run different executables (.exe) from labVIEW?
    One method is through the "system exec" vi. Other can be through the ActiveX (if the software is activex enabled)
    Any other method???????????
    Somil Gautam
    Think Weird

    I usually use this vi that calls the shell32.dll.   LV 8.6.1
    Just input the path to the program or file you want to open.
    Robert Fogg
    Certified LabVIEW Architect
    Attachments:
    Open_File_Program.vi ‏11 KB

Maybe you are looking for