Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / February 2004

Tip: Looking for answers? Try searching our database.

Suppressing an error message

Thread view: 
Prabh - 26 Feb 2004 18:13 GMT
Hello all,
From my Java program, I'm constructing a cmd-line one-liner and
running it from the shell on various platforms.

Is there any platform independent way to suppress error messages from
the cmd-line?
e.g., if the program does a "ls somefile.txt" on Unix and an analogous
"dir somefile.txt" on WIN, I want to suppress the error msgs, if
somefile.txt is not present.

In Unix, I could do a "ls somefile.txt 2> /dev/null".
But, is there a platform independent way to do the suppression.

Alternatively, how does one suppress the error msgs from WIN cmd? :)

Thanks for your time,
Prab
Ryan Stewart - 27 Feb 2004 01:16 GMT
> Hello all,
> From my Java program, I'm constructing a cmd-line one-liner and
[quoted text clipped - 13 lines]
> Thanks for your time,
> Prab
Why not simply use Java to ensure the directory exists before running the
command?
Prabh - 27 Feb 2004 13:39 GMT
> > Hello all,
> > From my Java program, I'm constructing a cmd-line one-liner and
[quoted text clipped - 15 lines]
> Why not simply use Java to ensure the directory exists before running the
> command?

Oops, I'm sorry I wasnt clear.
The "ls" and "dir" was just examples of a cmd. Bad examples :)

This is a one-liner which is same across all platforms and I wanted to
suppress the error msgs from it in case anything went wrong. Theres no
real need to understand what went wrong with the cmd.

Thanks for your time,
Prab
Chris Smith - 27 Feb 2004 14:36 GMT
> Oops, I'm sorry I wasnt clear.
> The "ls" and "dir" was just examples of a cmd. Bad examples :)
>
> This is a one-liner which is same across all platforms and I wanted to
> suppress the error msgs from it in case anything went wrong. Theres no
> real need to understand what went wrong with the cmd.

If you're using Java's Runtime.exec to run them, then standard error and
standard output are already captured for you, so you can just read and
ignore the contents.  If you're running the commands some other way, you
need to tell us how you're doing the running.

Signature

www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Prabh - 27 Feb 2004 23:02 GMT
> > Oops, I'm sorry I wasnt clear.
> > The "ls" and "dir" was just examples of a cmd. Bad examples :)
[quoted text clipped - 7 lines]
> ignore the contents.  If you're running the commands some other way, you
> need to tell us how you're doing the running.

I'm sorry if I was not clear.
I'm writing a new version control task for our ANT build process.
The version control is ClearCase and the task is to run ClearCase's
command:
"cleartool ls -d", which would run an ls on the present working dir.

Relevant portion:
====================================================

public class CCLs extends ClearCase
{
 Commandline cmdLine = new Commandline () ;
 cmdLine.setExecutable(getClearToolCommand()) ;
 cmdLine.createArgument().setValue("ls") ;
 moreOptions(cmdLine) ;
.....
}

In moreOptions:
=========================

public void moreOptions(Commandline more_cmdLine)
{
 more_cmdLine.createArgument().setValue("-d");
 more_cmdLine.createArgument().setValue(".");
....
}

The above tries to construct a cmd-line:  "cleartool ls -d ."
I wanted to add "redirect STDERR"  and suppress error msgs in case the
above cmd fails for any reason. Its not malicious and theres no reason
to track it.

I was thinking of adding "> /dev/null" to the above construct.

Thanks for your time,
Prab
Chris Smith - 28 Feb 2004 18:47 GMT
> I'm sorry if I was not clear.
> I'm writing a new version control task for our ANT build process.
> The version control is ClearCase and the task is to run ClearCase's
> command:

Okay.  Sorry, I'm not familiar with the Commandline class you use below.  
Perhaps someone who knows what third-party tool you're using there can
help you.

Signature

www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.