How to trap Command Line errors

Sigh.  I have searched for 3 hours to the answer for my question.  I'm new to scripting, so perhaps this is the problem in my not finding a solution.
In a nutshell, I simply want to gracefully trap command line usage of a script.  I want to have my script accept a parameter (ie. a value) and a switch.
Example:  <script> -path <path> -set
The problem is that i cannot trap incorrect usage.  I would prefer <path> to be position one, and -switch to be position 2 of the parameters passed to the script.  I have not tried this "outside" of PS v2.0 ISE (ie. Powershell.exe). 
Of course, I would love it to work in both environments.
I KNOW that the ISE will prompt for missing mandatory parameters.  Great.  But incorrectly specified parameters causes Powershell ISE to "bomb-out".  That is, displaying error messages to an uninformed user whom views it as unintelligible.
Example of incorrect usage:  <script> -pat <path> -set
Again, I would LOVE to trap this, and display correct USAGE to the screen.  Unfortunately, this produces a Powershell error message which has proved unintelligible to "simple" users.
Perhaps I must accept that this is not possible in Powershell v2.0.  I simply want to program my script to CATCH this error and take the desired action.
HELP!!!  To the knowledgeable and generous Scripting Professionals.
If the directions say go straight, but I turn left, then right: Will I still get there?

Okay, I stripped down the script:
<#
===============================================================================
PQSC PowerShell Source File
NAME   :
AUTHOR : PQSC.Programmer
DATE   :
COMMENT: Expects -->U:\Users\Public\Public Programs\PQSC\Scripts<-- appended to Execution Path
         CommandLine to Test=powershell -debug -command "U:\Users\PQSC.Programmer\Documents\WindowsPowerShell\Get-FilesWithArchiveBitSet.ps1" -x
===============================================================================
#>
<# ---------------------------------------------
# Param1 is mandatory, Param2 is optional.
# Param1 should be:  -path <path>
# Param2 should be:  -Set
#>
[CmdletBinding()]
Param(
    [parameter(Mandatory=$true,Position=1)]
    [AllowNull()]
    [AllowEmptyString()]
    [String]
    $Path,
    [switch]
    $Set_Archive
PRODUCES THIS ERROR in PowerShell v2.0 ISE when invoke with:
powershell -debug -command "U:\Users\PQSC.Programmer\Documents\WindowsPowerShell\Get-FilesWithArchiveBitSet.ps1" -x
powershell.exe : Missing expression after unary operator '-'.
At line:1 char:11
+ powershell <<<<  -debug -command "U:\Users\PQSC.Programmer\Documents\WindowsPowerShell\Get-untitled2.ps1" -x
    + CategoryInfo          : NotSpecified: (Missing express...y operator '-'.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
At line:1 char:2
+ - <<<< debug -command U:\Users\PQSC.Programmer\Documents\WindowsPowerShell\Ge
t-untitled2.ps1 -x
    + CategoryInfo          : ParserError: (-:String) [], ParentContainsErrorR
   ecordException
    + FullyQualifiedErrorId : MissingExpressionAfterOperator
If the directions say go straight, but I turn left, then right: Will I still get there?

Similar Messages

  • Command line: Error: unable to open '/Applications/flex_sdk_4\frameworks\flex-config.xml'

    Hi,
    I am new to flex. I am trying to use the xmp sdk to create custom file info panels in photoshop.
    I am going through the example show in the adobe documentation 'Building a panel with Flex SDK'
    I got any running and I got all the files setup in the proper folders but I cannot for the life of me figure out why I keep getting this error.
    Buildfile: /Volumes/three/2011/XMP/test project/build.xml
    clean:
    buildPanel:
         [echo] --> Panel 'Test2'
        [compc] Adobe Compc (Flex Component Compiler)
        [compc] Version 4.5.1 build 21328
        [compc] Copyright (c) 2004-2011 Adobe Systems, Inc. All rights reserved.
        [compc] command line: Error: unable to open '/Applications/flex_sdk_4.5\frameworks\flex-config.xml'
        [compc] Use 'compc -help' for information about using the command line.
    BUILD FAILED
    /Volumes/three/2011/XMP/test project/build.xml:20: compc task failed
    Total time: 616 milliseconds
    thanks,
    digitalkyle

    can you tell us where your services-config.xml file is
    located. can you make sure it is right under the "src" folder of
    the Flex Builder project.
    Hope this helps.

  • How to give command line arguments

    does anyone help me out in how to give command line arguments after run my program
    m using netbeans6.0.1

    If you want your program to take console input while it's running (as opposed to command line arguments, which are passed once, when you start your program), you can wrap a BufferdInputStream or a Scanner around System.in.
    [http://java.sun.com/docs/books/tutorial/essential/io/index.html]

  • File receive adapter command line error handling

    Hi,
    This is our requirement - After the file receive adapter, we need to run a script. Based on the return code of the script, we need to handle the error handling of the interface (i.e. send an email about the error).
    I have looked at the operating system command line in the file adapter. How does XI handle return codes for the command line? If the command line has a error return code, how to send an email from XI?
    If anyone has ideas on this topic, please respond!!
    thanks,
    lasya

    Hi,
    I don't think so, it is possible directly. You can not get the Response back to XI pipeline from the shell script.
    But you can think, if you are able to call this from Mapping.
    And one more option is using Transport Acknowledgement ( with BPM) if the file is not able to write into the target directory you can raise an alert-
    Blog on this-
    /people/michal.krawczyk2/blog/2006/06/22/xi-playing-with-the-file-adapters-acknowledgments
    Regards,
    moorthy

  • How we run command line commands in oracle

    Hi,
    In sql server i have an option "xp_cmdshell" i can run windows commands e.g "dir " using query analyzer.
    How can i do same thing in oracle
    Thanks in advance.
    Regards
    Faheem

    > MY SELECT:select OSexec('dir') as STDOUT from dual;
    ERROR:-1command[dir] The handle is invalid.
    In the sample code, I've executed a Linux/Unix program called date, physical file /usr/bin/date.
    Is there a DATE.EXE or a DIR.EXE program that you can execute on Windows?
    No. Both DATE and DIR are commands of a program - a 32bit console program called CMD.EXE.
    Your confusion stems from thinking that OSEXEC is calling the Windows shell command line. It is not. It is not calling CMD.EXE and passing Window Shell Commands to CMD.EXE.
    OSEXEC is calling, via Java, the Win32 API call called CreateProcess(). This is a call to the Win32 kernel. It requests the kernel to load an executable program as a process image.
    The kernel expects an EXE (or executable) file to load. You are passing it a command from a program. You just as well can pass it a Java command, a MS Access Basic Command, an Excel Macro, etc... Same thing. The kernel has no idea that this "command" needs another program to be loaded, and that command be "passed" somehow to that program.
    So, you need to call CMD.EXE via OSEXEC. And you can pass parameters to it. Open a Command Console and type cmd /? for help on the command line switches and parameters for CMD.EXE.
    I believe the following should work:
    SQL> select OSEXEC( 'c:\windows\system32\cmd.exe /c date /t') from dual;

  • How to pass command-line options to app using the "open" command?

    I am using jedit, and since I'm doing a lot of stuff in a shell, I'd really like to launch it from the command line as though I'd opened from finder, so I wrote a script that contains this:
    open -a /Applications/Jedit.app "$@" &
    This works well for everything except NEW files, where I get this error:
    2007-02-16 19:29:48.072 open[1032] No such file: /Users/millerti/projects/ateon/new_file
    Is there a way I can override this?
    So, it occurred to me that I might try running jedit directly this way:
    /Applications/Jedit.app/Contents/MacOS/jedit -- "$@" &
    The trouble is that this suffers all sorts of weird problems. For instance, if there's already a jedit running, it launches another one (despite the fact that -server is default). Moreover, the file it opens, existing or not, is not the one I specify. If I'm in ~/mydir and I open ./myfile, jedit opens instead /Applications/myfile.
    Obviously, I'm doing something wrong. Can someone help me figure out what open is doing internally so that I can launch jedit compatible with how open does it so that I can both open existing files and create new ones the same way from the command line?
    BTW, I can make more complex script.
    Also, if this isn't the right forum for this, can someone tell me where would be a better place to get the question answered?
    And I'm not expecting to get jedit support here. This isn't a jedit problem because it's behaving correctly.
    Thanks.

    Applications rarely take command line arguments. I don't know anything about Jedit, whether that is an exception, but you are not sending an argument to Jedit with the open command. The file name on your command line is an argument to the open command. The open command says "open this file with the specified application". The application doesn't see the argument. It sees the file exactly as if it were opened from the Finder. That's why naming a non-existent file doesn't work.
    What if you open Jedit with no file, create a new document in the application. (Again, I am not familiar with Jedit.)

  • How to use command line

    Hi All
    I want to create a Adobe Reader that when it startup will auto open a file.
    so I add this file to SYSDrive and modify startup command....I add a command line like @SYSDRIVE\test.pdf ,\Files\@SYSDRIVE\test.pdf or c:\test.pdf....
    but all testing will show error message~~
    about my purpose How ot set the "Command line" parameter ??
    thanks!!
    wyldkao

    Are you including the file with your virtualized app?

  • How to execute command line by Java

    Hi all,
    I have the following DOS command line that I need to execute it through Java:
    C:\Documents and Settings\Mxmler\Desktop\bin>vr1tovr2 Box.wrl -o Box2.wrl
    I know that I have to use Runtime.getRuntime().exec, But can anyone show me how to use it for the above?
    Thanks

    Mxmler wrote:
    I need your help please
    Forget about the first thread
    vr1tovr2 located inside a sub directory called converted (not in the main directory of the project constructed by eclipse)You have to tell the system where to find the program you're trying to run. You can specify the full path to the executable. Alternatively, you can specify the PATH environment variable when you call exec() (and I presume there's something similar for java.lang.ProcessBuilder). Read the docs.
    Box.wrl & Box2.wrl (will be generated) both of them are located in another directory called usrYou can either specify full paths to those files, or you can set the current working directory when you call exec(). So you'd tell exec() that you're in the directory where those files are. Read the docs.
    I have tried to do the following and I got the following error message: CreateProcess error=2, The system cannot find the file specifiedYou need to do what I said above, in particular, the first one (where you tell the system where to find the program you're trying to run).
    String path = System.getProperty("user.dir");
    String userFolder = "usr";
    String fileName = "mxmler";
    String extension = ".wrl";
    Runtime.getRuntime().exec("vr1tovr2 "
                + Key.QUOTE
                + path
                + Key.FORWARD_SLASH
                + userFolder
                + Key.FORWARD_SLASH
                + fileName + extension
                + Key.QUOTE
                + " -o "
                + Key.QUOTE
                + path
                + Key.FORWARD_SLASH
                + userFolder
                + Key.FORWARD_SLASH
                + fileName + "v2" + extension
                + Key.QUOTE);If you're going to break it down like that, then don't use the version of exec() that takes a single String for the whole command line. Use the version of exec() that takes an array of Strings (the first String in the array is the program to run, and the remaining strings in the array are arguments to that program).

  • Command line error on Windows server 2008, GUI works

    I'm running Windows Server 2008 with a Blackmagic Decklink card. Everything works fine with the GUI but when I try to start from command line it extis with an error (see attached image).
    Note: I have the desktop experience enabled.

    I came across the identical problem with an Osprey card. I did some digging and for some reason, on Windows Server 2008, the "Desktop Experience" must be enabled for the command line version of FMLE to function. Not sure why this is, but it worked for me. Here's the note from Microsoft on how to enable this feature on your server...
    http://technet.microsoft.com/en-us/library/cc772567.aspx

  • How to run command line argument programe

    Hi guys, I am doing pass command line argument programe in java but I don't know how to run this programe. Path for this programe in my my computer is C:\Users\Desktop\Mainjava\mycode\CommandProgjava*
    {code/}
    public class CommandProg
    public static void main(String[] args)
    System.out.println("d");
    for (int i = 0; i < args.length; i++)
    System.out.println(args);
    {code/}
    Where i need to go and what command i need to give so i can execute this programe(I am using window vista). I only know i have to give
    this command some where CommandProg arg1 arg2 arg3 arg4. Output should be
    Output:
    arg1
    arg2
    arg3
    arg4
    Please help me, Thanks in advance.
    Edited by: JayVirk on Dec 30, 2007 11:33 AM

    Jay,
    Your question isn't very clear, hence Joerg's well meaning but irrelevant advise.
    Do you mean:
    I've written a simple program in java which echos
    it's command-line arguments to back to the console.
    Here's my code:
    package forums;
    public class ArgsEchoer
      public static void main(String[] args) {
        for (String arg : args) {
          System.out.println(arg);
    But can't figure out how to compile and run the program.
    I'm using winblows shista, and it's cr@p.
    Please help me, Thanks in advance.So... where are you at? Have you installed the JDK (java development kit)? Which version? Is your path set? Is your classpath set?
    Start here: http://java.sun.com/developer/onlineTraining/new2java/

  • How to run command line tool in my program???

    Hi,all,I've got some tools that are usually,or take JDK for example,if we are not using an IDE,we need to open the command prompt,and then use the javac command to compile the source files and the "java "command to run the program,and both of them accept some command line params.The problem is that how could i integrate the tools in my own program,like JBuilder or some other IDE,you configure the params and compile and run in the IDE which don't need to open a command line prompt.Hope i have got my question clear:)
    Best regards..

    jesperdj ,thanks:)
    actually,i am using eclipse to run my ant tasks programmatically,but I got trouble with the AntRunner class.it seems that i should config a proper classloader for it,but i just don't know how.please lend a hand:)thanks
    robin

  • How to add command line arguments to shortcuts in the LV8.5.1 installer

    I want to create multiple shortcuts to my LV program, each with different command line arguments.
    I can do this manually.
    I want the installer to generate these shortcuts.
    I can add different shortcuts in de installer build specification, but I cannot add commandline arguments in the shortcuts.
    Does anyone know how to do this?
    Rindert 

    Hello Forum,
    Does anyone have any better data for this?  I would also like to create an installer using Labview Project Explorer tool (Build Specification->Installer), and I have a need to create some shortcuts to some EXE's (VS.NET built, not LV) which need to have some arguments passed.  I just verified that LV8.6 still does not seem to offer the option of passing arguments when creating shortcuts.  Is this correct?   Creating stub EXE's or batch files isn't a good option for my project, so I'd like to have someone confirm if LV installer tool can't create shortcuts w/ arguments before I fire up InstallShield.
    Regards!

  • Robohelp 7 HTML command line error

    I am trying to setup command line compilation for the project
    and i get this error from RHCL.exe
    Scanning project for compilation....
    Scanning finished.
    Error: Failed to create TRS file. Please use RoboHelp to
    recover the project.
    Unexpected Error: Failed to prepare single source data for
    RHCL. Please try to compile it in RoboHTML.
    The project is under source control

    Hi Mykola -
    Welcome aboard! First, let me ask you this: have you used
    command line compilation successfully before in this or any other
    project? And can you generate successfully in this project using
    the UI?
    It would be helpful if you would post your command line so
    that I can see the format.
    I don't think it matters that your project is
    source-controlled. I generate both types via the command line, and
    it's not a problem.
    G

  • Calling this simple servlet from command line -- ERRORS!

    Below is my servlet. I call from command line via:
    java BatchServlet
    and I get:
    Exception in thread "main" java.lang.NoClassDefFoundError: BatchServlet
    IS there a reason for this
    import java.io.IOException;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class BatchServlet extends HttpServlet implements Runnable{
    static Thread t = null;
    public void init(ServletConfig c) throws ServletException{
    super.init(c);
    if (t==null){
    t = new Thread(this);
    t.start();
    public void run(){
    while (true){
    try{
    Thread.sleep(5000);
    }catch (InterruptedException ie){
    ie.printStackTrace();
    System.out.println("Wake up");

    Same error with this little prog.....
    Notice main method
    package wch.util;
    import java.io.IOException;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class test {
    public void main(){
    System.out.println("test");

  • How to pass command line parameters in calling ant file

    Hi All, I m using a Build file which calls another build file.
    That build file is run from the command prompt by give ant -lib <path of jars it needs for executing>.
    Now i m calling this file from main build file but it does not work as i m not able to set <b>-lib </b>.
    Pls can anybody let me know how to set such command line parameters to call the build file in ant script.
    Thanks in Advance.
    Ketan.B.Parekh

    Create the control file dynamically (and fill one of the columns with the file name as a constant) before you start SQL*Loader
    Another option is to use external tables
    Re: Data Loading
    Message was edited by:
    Jens Petersen

Maybe you are looking for

  • Video Out in Boot Camp with Windows XP

    Sorry, this is my first help request... i hope i write in a correct section. I installed Windows XP SP2 with boot camp in my Mac Book Pro. I have the third part MiniDisplay Port to HDMI adapter with audio. I use it for projector. I always use it with

  • Using the New Mac Pro (can) - AE will not let me use Race Traced 3-D

    Using the New Mac Pro (can) - AE will not let me use Race Traced 3-D Hi, I'm using the new Mac Pro 2.7 GHz 12-core Intel Xeon E5 64 GB 1867 MHz DDR3 AMD FirePro D700 6144 MB OSX 10.9.2 I'm using After Effects 12.2.1.5 When I attempt to invoke the rac

  • I can't move music files to different folders in my itunes library

    First, I have not created files in my itunes library for a while, and I could swear it was a lot easier years ago! ALL that I want to do is add the new music I've purchased or recently added to a folder that already exists in the playlist. 1) All my

  • How to use a collection type of bind variable for execute dynamic statement

    Hi, We have a case where we copy selective data from Schema A To Schema B in one oracle database. The copy is achieved by using execute immediate 'insert into '||target_schema||'.tablea select * from '||from_schema||'.table a where a.id in (select te

  • Compressor 4 drops frames when converting 25fps image sequences

    I am using Compressor 4 to batch convert 30fps and 25fps 1080 tiff image sequences to Uncompressed 10bit 422. I have created custom presets for both 30fps and 25fps. The 30fps conversions are fine. But the 25fps conversions have missing or dropped fr