小编Bha*_*rat的帖子

通过Java程序"Sudo su - weblogic"?

我正在尝试连接我的远程unix机器并使用java程序执行一些ssh命令.

connection = new Connection(hostname);                                                  
connection.connect();
boolean isAuthenticated = connection.authenticateWithPassword(username, password);
if (isAuthenticated == false)
    throw new IOException("Authentication failed.");    
Session session = connection.openSession();
session.execCommand("sudo su - weblogic");  
Run Code Online (Sandbox Code Playgroud)

这里需要密码和ofcrs,我无法提供,因为没有终端.因此创建了一个user.sh文件@我的unix用户主目录(/home/..../bharat),内容如下.

echo <mypassword> | sudo -S su - weblogic
sudo -S su - weblogic
Run Code Online (Sandbox Code Playgroud)

但现在如果我像下面这样调用bash user.sh

session.execCommand("bash user.sh"); 
Run Code Online (Sandbox Code Playgroud)

在我的用户使用java登录后,它会给出以下错误,但无法确定解决方案.

sudo: sorry, you must have a tty to run sudo
sudo: sorry, you must have a tty to run sudo
Run Code Online (Sandbox Code Playgroud)

请帮忙 :)

发送的响应("cd /u02/app/oracle/xyz/admin/domains/11.1.1.9/xxxx_xx_xxx_xxx.domain/shared/logs/xxxx"); 在下面 -

突出显示的红色==>显示响应,我现在已经到了.

突出显示蓝色==>预期响应.

如果通过拆分相同的命令发送4个较小的命令,突出显示的绿色==>工作正常.

在此输入图像描述

java unix ssh shell weblogic

10
推荐指数
1
解决办法
379
查看次数

android.app.ServiceConnectionLeaked:Activity ... MainActivity泄露了ServiceConnection ... MainActivity $ 1 @ e794142最初绑定在这里

它的失败@下线 -

bindService(intent, m_serviceConnection, Context.BIND_AUTO_CREATE);
Run Code Online (Sandbox Code Playgroud)

以下是追踪....

Activity com.example.alwaysrunningprocesswithcallanswertap.MainActivity has leaked ServiceConnection com.example.alwaysrunningprocesswithcallanswertap.MainActivity$1@e794142 that was originally bound here
android.app.ServiceConnectionLeaked: Activity com.example.alwaysrunningprocesswithcallanswertap.MainActivity has leaked ServiceConnection com.example.alwaysrunningprocesswithcallanswertap.MainActivity$1@e794142 that was originally bound here
    at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:1077)
    at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:971)
    at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1774)
    at android.app.ContextImpl.bindService(ContextImpl.java:1757)
    at android.content.ContextWrapper.bindService(ContextWrapper.java:539)
    at com.example.alwaysrunningprocesswithcallanswertap.MainActivity.onCreate(MainActivity.java:48)
    at android.app.Activity.performCreate(Activity.java:5990)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)   
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
    at android.app.ActivityThread.access$800(ActivityThread.java:151)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5257)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Run Code Online (Sandbox Code Playgroud)

MainActivity.class

public class MainActivity extends Activity 
{
    CallNotifierService m_service;
    boolean isBound = …
Run Code Online (Sandbox Code Playgroud)

java android

7
推荐指数
1
解决办法
2万
查看次数

如何获得1个月的GPRS移动数据使用?

我已经搜索了很多关于这一点.在任何地方找到相同的代码,部分地解决了目的.正如API文档所述,它会在设备重启后重置计数器.有时,即使没有重启,计数器也会重置.下面是代码

float totalRxBytes = (float)TrafficStats.getTotalRxBytes()/(float)1048576;  // Received
float totalTxBytes = (float)TrafficStats.getTotalTxBytes()/(float)1048576;  // Sent
float mobRxBytes = (float)TrafficStats.getMobileRxBytes()/(float)1048576;
float mobTxBytes = (float)TrafficStats.getMobileTxBytes()/(float)1048576;
float wifiRxBytes = totalRxBytes - mobRxBytes;
float wifiTxBytes = totalTxBytes - mobTxBytes;  
Run Code Online (Sandbox Code Playgroud)

但我无法想出任何方式从特定日期或一个月获得这些数据?请帮忙.任何指针将不胜感激.谢谢.

android gprs network-traffic android-trafficstats

6
推荐指数
1
解决办法
364
查看次数

TelephonyManager也可以提供SIM 2的详细信息,如isRoaming等.?

如下所示 - TelephonyManager仅提供SIM1的详细信息?

TelephonyManager  telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.isNetworkRoaming()
Run Code Online (Sandbox Code Playgroud)

android

5
推荐指数
1
解决办法
3915
查看次数

即使在一个寄存器之后,Android BroadcastReceiver onReceive()在android 5.1.1上调用了两次

我无法弄清楚下面的代码有什么问题.我还检查了两次注册接收器.但事实并非如此.或者可能是我遗失了一些东西.可以请任何帮助.我真的需要它.:(

import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.IBinder;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;

/**
 * 
 * @author Bharat
 *
 */
public class CallNotifierService extends Service 
{
    private static final String ACTION_IN = "android.intent.action.PHONE_STATE";
    private static final String ACTION_OUT = "android.intent.action.NEW_OUTGOING_CALL";
    private CallBr br_call;

    @Override
    public IBinder onBind(Intent arg0) 
    {
        return null;
    }

    @Override
    public void onDestroy() 
    {
        Log.d("service", "destroy");
        this.unregisterReceiver(this.br_call);
        super.onDestroy();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId)
    { …
Run Code Online (Sandbox Code Playgroud)

android broadcastreceiver android-broadcastreceiver

4
推荐指数
2
解决办法
4483
查看次数

即使在使用START_STICKY之后,服务也不会始终运行

问题

即使在使用START_STICKY之后,服务也不会始终运行.

有时候我没有得到任何Togoing Action for Outgoing,这是否意味着服务在一段时间后停止了?

我的要求

每当用户通过电话拨打电话时,应用程序都会显示Toast.为此,我使用BroadcastReceiver来点击调用操作和服务(始终运行Receiver).一旦我开始这项活动,它就会在拨打电话时开始显示吐司..但不是总是.

以下是完整的代码 -

MainActivity.class

public class MainActivity extends Activity 
{
    CallNotifierService m_service;
    boolean isBound = false;

    private ServiceConnection m_serviceConnection = new ServiceConnection() 
    {
        @Override
        public void onServiceConnected(ComponentName className, IBinder service) 
        {
            m_service = ((CallNotifierService.MyBinder)service).getService();
            Toast.makeText(MainActivity.this, "Service Connected", Toast.LENGTH_LONG).show();
            isBound = true;
            Intent intent = new Intent(MainActivity.this, CallNotifierService.class);
            startService(intent);
        }

        @Override
        public void onServiceDisconnected(ComponentName className) 
        {
            m_service = null;
            isBound = false;
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Intent intent …
Run Code Online (Sandbox Code Playgroud)

service android

3
推荐指数
1
解决办法
4427
查看次数

枚举列表删除问题

任何人都可以帮助我解决问题吗?

public static void main(String[] args) 
{
    List<TestEnum> list1 = new ArrayList<TestEnum>();
    list1.add(TestEnum.ONE);
    list1.add(TestEnum.TWO);
    list1.add(TestEnum.THREE);

    System.out.println(list1);
    System.out.println(list1.remove(TestEnum.TWO));
    System.out.println(list1);

    System.out.println("-----------------------");

    TestEnum[] xx = new TestEnum[]{TestEnum.ONE, TestEnum.TWO, TestEnum.THREE};
    List<TestEnum> list2 = Arrays.asList(xx);

    System.out.println(list2);
    System.out.println(list2.remove(TestEnum.TWO));
    System.out.println(list2);
}
Run Code Online (Sandbox Code Playgroud)

以下是结果 -

[ONE, TWO, THREE]
true
[ONE, THREE]
-----------------------
[ONE, TWO, THREE]
Exception in thread "main" java.lang.UnsupportedOperationException
at java.util.AbstractList.remove(Unknown Source)
at java.util.AbstractList$Itr.remove(Unknown Source)
at java.util.AbstractCollection.remove(Unknown Source)
at Test.main(Test.java:24)
Run Code Online (Sandbox Code Playgroud)

请帮助 - 为什么会这样,我还检查了哈希码?

java enums enumeration list

0
推荐指数
1
解决办法
4123
查看次数