QueryCAT Logo
Search 5,000,000+ questions and answers.

Frequently Asked Questions

Sect. 18) How do I execute a command in my program?

Java Programmer's FAQ - Part D
Use Runtime.getRuntime().exec( myCommandString ) where myCommandString is something like "/full/pathname/command". An applet will need to be signed in order to allow this. If the pathname contains spaces, e.g. "c:\program files\windows\notepad", then enclose it in quotes within the quoted string. Or pre-tokenize them into elements of an array and call exec(String[] cmd) instead of exec(String cmd). From JDK1.3 there are two new overloaded Runtime.exec() methods. See similar questions...

Sect. 18) OK, how do I read the output of a command?

Java Programmer's FAQ - Part D
above (18.8, 18.9), adjusted like this: BufferedReader pOut= new BufferedReader( new InputStreamReader(p.getInputStream())); try { String s = pOut.readLine(); while (s != null) { System.out.println(s); s = pOut.readLine(); } } catch (IOException e) { } Another possibility is to read chunks of whatever length as they come in: ... p = r.exec(cmd); InputStream is = p.getInputStream(); int len; byte buf[] = new byte[1000]; try { while( (len = is. See similar questions...

How can I execute a command with system() and read its output into a program?

The C Language FAQ
Unix and some other systems provide a popen() routine, which sets up a stdio stream on a pipe connected to the process running a command, so that the output can be read (or the input supplied). See similar questions...

How do I execute command foo within function foo?

Z-Shell Frequently-Asked Questions
The command command foo does just that. You don't need this with aliases, but you do with functions. Note that error messages like zsh: job table full or recursion limit exceeded are a good sign that you tried calling 'foo' in function 'foo' without using 'command'. If foo is a builtin rather than an external command, use builtin foo instead. See similar questions...

Sect. 18) What are the naming conventions?

Java Programmer's FAQ - Part D
Package names are guaranteed uniqueness by using the Internet domain name in reverse order: com.javasoft.jag - the "com" or "edu" (etc.) part used to be in upper case, but now lower case is the recommendation. Class and interface names are descriptive nouns, with the first letter of each word capitalized: PolarCoords. Interfaces are often called "something-able", e.g. "Observable", "Runnable", "Sortable". See similar questions...

Sect. 18) How can I set a system property?

Java Programmer's FAQ - Part D
JDK 1.2 has System.setProperty( "property", "new value" ); Until then, you can get all the properties, and set just the one you want with code like this: System.getProperties().put("property", "new value" ); See similar questions...

How long does it take to execute a command?

FAQ about PMC Motion Controllers
For our MultiFlex and DCX Series of PCI-bus controllers (MultiFlex PCI 1440, MultiFlex PCI 1040, DCX-PCI300, DCX-PCI100, the command execution time is typically on the order of 50-100 microseconds per command. When using Pentiun III class computers or above, PMC's legacy ISA-bus controllers can achieve 1,000-1,500 commands and responses per second. For our PCI-bus controllers, the command rate is higher - typically in the range of 5,000-10,000 command-and-response cycles per second. See similar questions...

How do I execute a shell command via system exec?

The LabVIEW FAQ - The Block Diagram
The exec VI function can be used to send shell commands. Include the shell call with the commands that are desired. For example under Windows operating systems the call is to command.com. For example, the string to copy filea to a drive would be See similar questions...

How can I invoke an operating system command from within a program?

Infrequently Asked Questions in comp.lang.c
Ask the user to open a new shell. The best way to do this is system("echo Please open a new shell now."); sprintf(cmdstring, "echo Enter the command '%s' in it.", cmd); system(cmdstring); The traditional solution, pioneered by Microsoft, is to sell enough copies of your proprietary, slow, and limited software that everyone else supports your formats. See similar questions...

Sect. 18) How do I convert a String to an int?

Java Programmer's FAQ - Part D
There are several ways. The most straightforward is: String myString = numString.trim(); int i = Integer.parseInt(myString); long l = Long.parseLong(myString) or String myString = numString.trim(); i = Integer.parseInt(myString,myIntRadix); Note 1: There is a gotcha with parseInt - it will throw a NumberFormatException for String values in the range "80000000" to "ffffffff". You might expect it to interpret them as negative, but it does not. The values have to be "-80000000" . See similar questions...

Sect. 18) How do I convert an int to a string?

Java Programmer's FAQ - Part D
Try any of these: String s = String.valueOf(i); or String s = Integer.toString(i); or String s = Integer.toString(i, radix); or // briefer but may result in extra object allocation. String s = "" + i; Note: There are similar classes for Double, Float, Long, etc. See similar questions...

Sect. 18) How do I manipulate bits in Java?

Java Programmer's FAQ - Part D
Use bytes, shorts, chars, ints or longs if you need to manipulate no more than 64 bits at once. Use ~ for NOT, & for AND, | for OR, and ^ for XOR. Beware that the precedence for & | and ^ is not intuitive; they have lower precedence than == and !=, so you must write: if ((a & 1) == 1) rather than: if (a & 1 == 1) You can also shift bits with the <<, >> and >>> operators; >> is a signed shift and >>> is an unsigned shift. See similar questions...

Sect. 18) How can I clone using serialization?

Java Programmer's FAQ - Part D
Look at the code below, submitted by expert programmer John Dumas. It uses serialization to write an object into a byte array, and reads it back to reconstitute a fresh copy. This is a clever hack! import java.io.ByteArrayOutputStream; import java.io.ByteArrayInputStream; import java.io.ObjectOutputStream; import java.io. See similar questions...

How do I execute a servlet from the command line, or from Unix shell program or Windows BAT file?

jGuru: Servlets FAQ Home Page
Of course as with any Java class, you could put a "main" method in your class that extends HttpServlet, so you could run it (the main(), not the doGet... See similar questions...

How can I execute more than one command in the need-op settings?

The Eggdrop FAQ: Running the bot
The best is to create a separate procedure to handle everything you need: chanset <#channel> need-op "need_op_cmd <#channel>" proc need_op_cmd { channel } { command1 command2 ... } To do this, you need to edit the first line of the config to make it point to the full path of where your eggdrop binary is. For example you have See similar questions...

Sect. 18) Why can't I get String mutator methods to work?

Java Programmer's FAQ - Part D
Code like this seems to show that the calls don't work! String s = " hello "; s.trim(); s.toUpperCase(); Note again that Strings are immutable. This means that once a String has been initialized, its contents won't change. In the code above, the method calls return a different String with the desired alterations. But this new String is not assigned to anything, so the results are discarded. To see the changes, assign the results of the method call to the original String or to another String. See similar questions...

Sect. 18) How do I print the hex value of an int?

Java Programmer's FAQ - Part D
You can print the hex equivalent of an int with: int i = 0xf1; System.out.println("i is hex " + Integer.toHexString(i) ); See similar questions...

Sect. 18) How can you send a function pointer as an argument?

Java Programmer's FAQ - Part D
Simple answer: use a "callback". Make the parameter an interface and pass an argument instance that implements that interface. public interface CallShow { public void Show( ); } public class ShowOff implements CallShow { public void Show( ) { .... } public class ShowOff2 implements CallShow { public void Show( ) { .... } public class UseShow { CallShow savecallthis; UseShow( CallShow withthis ) { savecallthis = withthis; } void ReadyToShow( ) { savecallthis. See similar questions...

Sect. 18) How do I do I/O redirection using exec()?

Java Programmer's FAQ - Part D
This solution works on Unix platforms using either JDK 1.0.2, or JDK 1.1. The trick is to use an array of Strings for the command line: String[] command = {"/bin/sh", "-c", "/bin/ls > out.dat"}; If you don't do this, and simply use a single string, the shell will see the -c and /bin/ls and ignore everything else after that. It only expects a single argument after the -c. import java.io.*; import java.util. See similar questions...

Sect. 18) So why can't I exec common DOS commands this way (as in 18.8)?

Java Programmer's FAQ - Part D
The reason is that many of the DOS commands are not individual programs, but merely "functions" of command.com. There is no DIR.EXE or COPY.EXE for example. Instead, one executes the command processor (shell) explicitly with a request to perform the built-in command, like so: Runtime.getRuntime().exec("command.com /c dir") for example. On NT, the command interpreter is "cmd.exe", so the statement would be Runtime.getRuntime(). See similar questions...

Explore Other Topics

What is a "disclosure schedule"?
Q10: What should I write in my Study Plan?
When should I stop bottle- and breast-feeding?
Can I use bottled water, spring water, or tap water instead of distilled water for the experiment?
Why does draft beer give me a worse hangover than bottled beer?
Are SilverStar headlights high intensity discharge (HID) or Xenarc headlights?
Do plants really grow in the Plant Gel without soil?
What is Denier? What is Tex?
Where can I buy Epsom Salt?
Can HIV be spread through kissing?
How can I tell the difference between a cold and an allergy?
Can I re-seed my lawn after using a weed control product?
Can I synchronize with Microsoft Outlook?
Should you index foreign keys in a database table?
How do I change my Zippo Lighter Flint?
More Questions >>

© Copyright 2007-2010 QueryCAT
About • Webmasters • Contact