小编Poz*_*nux的帖子

简单的SSH连接JSch

我试图通过这个简单的例子来创造一些东西:

SSH,使用Android执行远程命令

我只是想看看我是否可以使用SSH从我的Android手机连接到Linux服务器,但它不起作用...

这是我的主要代码:

package com.example.ssh;

import java.util.Properties;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
import android.os.Bundle;
import android.app.Activity;

 public class MainActivity extends Activity {

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

    try
    {
        JSch jsch = new JSch();
          Session session = jsch.getSession("root","192.168.0.26", 22);
          session.setPassword("xxxxx");

          // Avoid asking for key confirmation
          Properties prop = new Properties();
          prop.put("StrictHostKeyChecking", "no");
          session.setConfig(prop);

          session.connect();

    }
    catch (Exception e)
    {
      System.out.println(e.getMessage());
    }
}
}
Run Code Online (Sandbox Code Playgroud)

我做错了什么 ?我没有错误消息,我的Linux上没有看到任何SSH连接.我添加了库jsch和jzlib.我没有问题与putty会话连接.

编辑1:事实上,我发现了一个错误,解释了为什么即使我不知道如何解决问题它也不起作用.错误是:

android.os.NetworkOnMainThreadException

所以它似乎意味着应用程序无法在其主线程上执行网络操作...

ssh android jsch

15
推荐指数
3
解决办法
3万
查看次数

从文件 1 中删除 Powershell 中文件 2 中存在的行

我有一个 file1.txt,其中包含:

一号线
2号线
3号线
4号线

我想从 file1.txt 中删除存在于另一个 file2.txt 中的所有行:

线 3 线
2

结果应该是:

线 1
线 4

我尝试使用此命令,但仅当我在 file2.txt 中有一行时才有效:

Get-Content C:\file1.txt | Where-Object {$_ -notmatch $(get-content C:\file2.txt)} 
Run Code Online (Sandbox Code Playgroud)

注意:我不想比较 2 个文件以查看它们是否相同。

任何的想法?我对 powershell 很陌生。

windows powershell file

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

动态壁纸图像

(对不起,我的英文不太好......希望你能理解我)

我的朋友是一个非常好的抽屉.我想帮助他成为一个好抽屉,让他成为一个用他的绘画动画的动态壁纸.

我希望他能画几帧并使用这些帧来制作动态壁纸,一个接一个地显示它们.

我正在努力展示一张图片,然后等一下,然后显示下一张图片.我很确定我不能成功,因为我没有使用正确的方法......

这是我到目前为止所做的事情:

public class Cercle extends WallpaperService
{
public void onCreate() 
{
    super.onCreate();
}

public void onDestroy() 
{
    super.onDestroy();
}

public Engine onCreateEngine() 
{
    return new CercleEngine();
}

class CercleEngine extends Engine 
{
    public Bitmap image1, image2, image3;

    CercleEngine() 
    {       
        image1 = BitmapFactory.decodeResource(getResources(), R.drawable.img1);
        image2 = BitmapFactory.decodeResource(getResources(), R.drawable.img2);
        image3 = BitmapFactory.decodeResource(getResources(), R.drawable.img3); 
    }

    public void onCreate(SurfaceHolder surfaceHolder) 
    {
        super.onCreate(surfaceHolder);
    }

    public void onOffsetsChanged(float xOffset, float yOffset, float xStep, float yStep, int xPixels, int yPixels) 
    {
        drawFrame();
    } …
Run Code Online (Sandbox Code Playgroud)

android image bitmap wallpaper live

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

在Bash中显示命令结果和行结果数

我使用一个命令,显示几行结果.我想看到结果,然后显示结果的行数.

今天我做:

my-command XXX    # to display the result  
echo "Number :" $(my-command XXX | wc -l)    # to display the number of lines
Run Code Online (Sandbox Code Playgroud)

但是如果我想改变命令,我必须改变它两次.是否有更好的方法来获得相同的结果?

bash awk

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

这是一个bash bug吗?(用ls列出目录)

如果我想列出以下目录中的所有文件和目录:

[root@centos2 dir1]# tree
.
+-- dir2
    +-- coucou.txt

1 directory, 1 file
Run Code Online (Sandbox Code Playgroud)

为什么dir2没有显示在下面?仅显示该文件.

[root@centos2 dir1]# ls -l *
total 0
-rwxr--r-- 1 root root 0 Dec  2 18:20 coucou.txt
Run Code Online (Sandbox Code Playgroud)

如果我复制目录和列表,它们都会显示:

[root@centos2 dir1]# cp -r dir2/ dir3
[root@centos2 dir1]# tree
.
+-- dir2
¦   +-- coucou.txt
+-- dir3
    +-- coucou.txt

2 directories, 2 files

[root@centos2 dir1]# ls -l *
dir2:
total 0
-rwxr--r-- 1 root root 0 Dec  2 18:20 coucou.txt

dir3:
total 0
-rwxr--r-- 1 root root 0 Dec …
Run Code Online (Sandbox Code Playgroud)

bash ls

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

标签 统计

android ×2

bash ×2

awk ×1

bitmap ×1

file ×1

image ×1

jsch ×1

live ×1

ls ×1

powershell ×1

ssh ×1

wallpaper ×1

windows ×1