SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP exec problem

    Hey there,

    I'm new to this exec() function, but i was told i can use it to run a java file.

    For example, if my php file is:

    exec("java.exe try2", $output, $return_var);
    $output_str = join($output, "\n");

    echo "<pre>The output was:\n".$output_str."\n\n";
    echo "The return value was ".$return_var."</pre>";


    and my java file is:

    public class try2{
    public static void main(String [] args)
    {
    System.out.println("hello");
    }

    }


    Then hello is printed in the PHP file, that works fine. but if my java file is a bit more complicated, like this file i downloaded, which uses javax.bluetooth, to detect bluetooth devices, no output is shown...

    import java.io.IOException;
    import java.util.Vector;
    import javax.bluetooth.*;

    /**
    * Minimal Device Discovery example.
    */
    public class RemoteDeviceDiscovery {

    public static final Vector/*<RemoteDevice>*/ devicesDiscovered = new Vector();

    public static void main(String[] args) throws IOException, InterruptedException {

    final Object inquiryCompletedEvent = new Object();

    devicesDiscovered.clear();

    DiscoveryListener listener = new DiscoveryListener() {

    public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) {
    System.out.println("Device " + btDevice.getBluetoothAddress() + " found");
    devicesDiscovered.addElement(btDevice);
    try {
    System.out.println(" name " + btDevice.getFriendlyName(false));
    } catch (IOException cantGetDeviceName) {
    }
    }

    public void inquiryCompleted(int discType) {
    System.out.println("Device Inquiry completed!");
    synchronized(inquiryCompletedEvent){
    inquiryCompletedEvent.notifyAll();
    }
    }

    public void serviceSearchCompleted(int transID, int respCode) {
    }

    public void servicesDiscovered(int transID, ServiceRecord[] servRecord) {
    }
    };

    synchronized(inquiryCompletedEvent) {
    boolean started = LocalDevice.getLocalDevice().getDiscoveryAgent().startInquiry(DiscoveryAgent.G IAC, listener);
    if (started) {
    System.out.println("wait for device inquiry to complete...");
    inquiryCompletedEvent.wait();
    System.out.println(devicesDiscovered.size() + " device(s) found");
    }
    }
    }

    }



    I was asked if it compiling and running RemoteDeviceDiscovery on cmd line worked, i tried it out, and noo it didnt!

    javac RemoteDeviceDiscovery.java

    and i get all these errors
    RemoteDeviceDiscovery.java:3: package javax.bluetooth does not exist
    import javax.bluetooth.*;
    ^
    RemoteDeviceDiscovery.java:19: cannot find symbol
    symbol : class DiscoveryListener
    location: class RemoteDeviceDiscovery
    DiscoveryListener listener = new DiscoveryListener() {
    ^
    RemoteDeviceDiscovery.java:19: cannot find symbol
    symbol : class DiscoveryListener
    location: class RemoteDeviceDiscovery
    DiscoveryListener listener = new DiscoveryListener() {
    ^
    RemoteDeviceDiscovery.java:45: cannot find symbol
    symbol : variable DiscoveryAgent
    location: class RemoteDeviceDiscovery
    boolean started = LocalDevice.getLocalDevice().getDiscoveryAgent().s
    tartInquiry(DiscoveryAgent.GIAC, listener);

    ^
    RemoteDeviceDiscovery.java:45: cannot find symbol
    symbol : variable LocalDevice
    location: class RemoteDeviceDiscovery
    boolean started = LocalDevice.getLocalDevice().getDiscoveryAgent().s
    tartInquiry(DiscoveryAgent.GIAC, listener);
    ^
    5 errors


    It appears like it can't find the bluecove.jar, although i added it to the classpath and the path in the system variables...

    What should i do??

    Thanks alot!

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This isn't a php issue.
    This is java code that you have not been able to compile. Once you're able to get the code compiled and working, then you can worry about using php to execute it the program.

    Make a post in the java forum. Use the forums syntax highlighting feature when posting code. http://www.sitepoint.com/forums/misc.php?do=bbcode


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •