小编use*_*597的帖子

java runtime.getruntime()从执行命令行程序获取输出

我正在使用运行时从我的Java程序运行命令提示符命令.但是我不知道如何获得命令返回的输出.

这是我的代码:

Runtime rt = Runtime.getRuntime();

String[] commands = {"system.exe", "-send" , argument};

Process proc = rt.exec(commands);
Run Code Online (Sandbox Code Playgroud)

我尝试过,System.out.println(proc);但没有返回任何东西.该命令的执行应返回由分号分隔的两个数字,我怎样才能在变量中打印出来?

这是我现在使用的代码:

String[] commands = {"system.exe", "-get t"};

Process proc = rt.exec(commands);

InputStream stdIn = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(stdIn);
BufferedReader br = new BufferedReader(isr);

String line = null;
System.out.println("<OUTPUT>");

while ((line = br.readLine()) != null)
     System.out.println(line);

System.out.println("</OUTPUT>");
int exitVal = proc.waitFor();
System.out.println("Process exitValue: " + exitVal);
Run Code Online (Sandbox Code Playgroud)

但我没有得到任何东西作为我的输出,但当我自己运行该命令它工作正常.

java runtime

131
推荐指数
7
解决办法
23万
查看次数

将img标记放在href标记内会导致IE中的图像边框

我有一些HTML,我在href标签内部有img标签用作按钮.一切正常,只有当我在IE中打开它时,我会在img标签周围找到一个边框.

这是一些代码:

<a href="javascript:changecolor(1)" title="Click Again to Change Color" style="cursor:pointer; text-decoration:none"><img src="button.png" width="25" height="25" style="margin-top:600px;" /></a>
<a href="javascript:changecolor(2)" title="Click Again to Change Color" style="cursor:pointer"><img src="button.png" width="25" height="25" style="margin-top:600px;" /></a>
<a href="javascript:changecolor(3)" title="Click Again to Change Color" style="cursor:pointer"><img src="button.png" width="25" height="25" style="margin-top:600px;" /></a>
<a href="javascript:changecolor(4)" title="Click Again to Change Color" style="cursor:pointer"><img src="button.png" width="25" height="25" style="margin-top:600px;" /></a>
<a href="javascript:changecolor(7)" title="Click Again to Change Color" style="cursor:pointer"><img src="button.png" width="25" height="25" style="margin-top:600px;" /></a>
<a href="javascript:changecolor(6)" title="Click Again to Change Color" style="cursor:pointer"><img src="button.png" width="25" height="25" style="margin-top:600px; …
Run Code Online (Sandbox Code Playgroud)

html css internet-explorer

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

滚动叠加div而不滚动整个页面

我有一个主页面,上面有一些内容.然后我有一个弹出的模态比屏幕本身长,所以我必须滚动才能看到它.我需要对CSS做什么才能只进行模态div滚动而不是整个页面?

这是模态的CSS

#overlay {
    visibility: hidden;
    position: absolute;
    left: 45%;
    width:auto;
    border:1px solid #A17E13;
    height:auto;
    text-align:left;
    z-index: 1000; 
}
#overlay div {
    background-color:#FCFBEC;
}
Run Code Online (Sandbox Code Playgroud)

这是HTML:

<html><body>
    <div>main page</div>
    <div id="overlay">
    <div>
        <div>
             <asp:Label ID="test">Text for modal here</asp:Label>
        </div>
    </div>
    </div>
</body></html>
Run Code Online (Sandbox Code Playgroud)

html css

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

UserInfo传递yes点击功能

我正在使用ssh工具与学校服务器建立ssh连接,我使用的示例是来自创建ssh连接的源代码.我的问题是我不想要任何用户输入提示但是弹出提示说无法建立主机的真实性并且用户需要按是继续,我怎样才能为程序编写代码以接受提示本身.

Session session = jsch.getSession(user, host, 22);
//username and host I can input directly into program so thats not a problem
// username and password will be given via UserInfo interface.
UserInfo ui = new MyUserInfo();

//this is the part that uses the UserInfo, which pulls up a prompt
//how can I code the prompt to automatically choose yes?    
session.setUserInfo(ui);
session.setPassword("password");
session.connect();
String command = JOptionPane.showInputDialog("Enter command", "set|grep SSH");
Run Code Online (Sandbox Code Playgroud)

java ssh

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

单击按钮后keylistener无法正常工作

我有一个keylistener附加到我的框架在java,我可以检测到按键时按键,但奇怪的事情正在发生.我的游戏是一个扫雷游戏,我有一个重启按钮,基本上清理板并重新调整它.奇怪的是,当我用鼠标点击按钮时,一切都清晰,并且电路板被重新启动但是keylistener停止工作.更奇怪的是,我有一个jmenuitem基本上自动点击按钮.所以就像restartbutton.doclick()

如果我点击jmenuitem重新启动它重新启动精细清除一切,keylistener仍然起作用.我甚至可以看到点击按钮.任何想法为什么会发生这种情况?

谢谢

这是附在我的主框架上.这是单击按钮后停止工作的监听器.

frame.addKeyListener(new KeyListener(){


       public void keyReleased(KeyEvent e){


       }

       public void keyPressed(KeyEvent e){

       System.out.println("hey");
       int keycode = e.getKeyCode();

       if(e.isControlDown() & keycode==KeyEvent.VK_C){

      balh blah balh
       }

       }

       public void keyTyped(KeyEvent e){


       }

       });
Run Code Online (Sandbox Code Playgroud)

java swing keylistener

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

从Active Directory PrincipalContext获取所有用户

我使用以下代码来访问我的AD中的用户列表,但是在我将用户添加到组合框的行中,我得到一个空引用异常.

PrincipalContext AD = new PrincipalContext(ContextType.Domain, "mydomainip");
UserPrincipal u = new UserPrincipal(AD);
PrincipalSearcher search = new PrincipalSearcher(u);

foreach (UserPrincipal result in search.FindAll())
{
    if (result.DisplayName != null)
    {
        comboBox2.Items.Add(result.DisplayName);
    }
}
Run Code Online (Sandbox Code Playgroud)

知道我做错了什么吗?

我用a替换了组合框,Console.WriteLine(result.DisplayName)它工作正常.

c# active-directory

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

发送电子邮件附件后删除c#中的文件

我有以下代码基本上将文件附加到电子邮件消息然后附加所有附件并发送电子邮件后,我尝试删除所有文件,但我得到一个正在使用的文件异常.我相信错误就在这一行

Attachment data = new Attachment(file, MediaTypeNames.Application.Octet);
Run Code Online (Sandbox Code Playgroud)

我尝试使用此代码,但我收到一封无法发送的电子邮件

using Attachment data = new Attachment(file, MediaTypeNames.Application.Octet)){
//and the rest of the code in here.

}


foreach (KeyValuePair<string, string> kvp in reports) {
    browser.GoTo(kvp.Value);
    Thread.Sleep(1000);

    System.IO.File.Move(@"C:\Reports\bidata.csv", @"C:\Reports\"+kvp.Key.ToString()+".csv");

    string file = @"C:\Reports\" + kvp.Key.ToString() + ".csv";

    Attachment data = new Attachment(file, MediaTypeNames.Application.Octet);

    // Add time stamp information for the file.
    ContentDisposition disposition = data.ContentDisposition;
    disposition.CreationDate = System.IO.File.GetCreationTime(file);
    disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
    disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
    // Add the file attachment to this e-mail message.

    mail.Attachments.Add(data); …
Run Code Online (Sandbox Code Playgroud)

c#

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

该字符串未被识别为有效的DateTime。从索引0开始有一个未知词

我有以下C#在尝试将字符串解析为datetime时出现上述错误。

DateTime backupdate = System.Convert.ToDateTime(imageflowlabel.Text);   
DateTime currentdate = System.DateTime.Now.AddHours(-2);    
int result = currentdate.CompareTo(backupdate);
Run Code Online (Sandbox Code Playgroud)

imageflowlable.text 看起来像这样 2012-04-15 15:23:34:123

关于如何转换此的任何想法?

谢谢

c# datetime

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

从另一个actionlistener调用actionlistener

我有一个actionlistener,当我点击一个按钮时会激活它,我可以调用它,我有另一个actionlistener用于另一个按钮调用它重启.我想要做的是当我单击一个方框按钮除了在该actionlistener中调用它自己的actionlistener之外我想在满足某个条件时调用actionlistener来重启.有任何想法吗?

java swing jbutton actionlistener

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

Excel不插入前导零

我使用Office OpenXml写入Excel文件.该文件是一个模板,因此它已经包含了我的列的所有标题和格式.我将具有前导零的数字插入到"特殊"列中,该列基本上是10位数字.但是在我的代码中,我可以看到它正在设置值,例如0000000004.工作表中的结果,该4单元格中的值和实际单元格显示0000000004.

这是我写入单元格的代码.

  if (reader[2].ToString().Length < 9)
  {


        myworksheet.Cell(firstrow, 12).Value = reader[2].ToString(); //0045678945

  }
  else
  {
        myworksheet.Cell(firstrow, 12).Value = reader[2].ToString().Substring(0, 9); //0045678945

  }
Run Code Online (Sandbox Code Playgroud)

当我像上面所述打开excel表时,我的价值45678945不是0045678945

任何帮助,将不胜感激.

c# openxml spreadsheetml openxml-sdk

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