输出数组到CSV文件输出行长度 - powershell

时间:2017-02-16 05:21:22

标签: powershell

我正在开发一个powershell脚本,它将nmap扫描数据从大量nmap .txt文件输出到CSV。每当我通过Export-Csv C:\ file.csv输出数据时,它输出的是行的长度,而不是实际的数据。

有什么建议吗?输出数组似乎是我遇到问题的原因。

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
boolean entryError = false; 
if(FoodName.getText().equals(""))
{
JOptionPane.showMessageDialog(null, "Enter the Horse Food Name.","Error.",JOptionPane.ERROR_MESSAGE); 
entryError = true; 

}
if(FoodQuantity.getText().equals("")&& entryError==false)
{
JOptionPane.showMessageDialog(null, "Enter the Horse Food                  
Quantity.","Error.",JOptionPane.ERROR_MESSAGE); 
entryError = true; 

}
if(FoodTime.getText().equals("")&& entryError == false)
{
JOptionPane.showMessageDialog(null, "Enter the Horse FoodTimes.","Error.",JOptionPane.ERROR_MESSAGE); 
entryError = true; 

  }

  if(entryError == false)
   {


try {
    FileWriter tWriter = new FileWriter("HorseNutrition.txt",true);
    PrintWriter tPrinter = new PrintWriter(tWriter);

    tPrinter.println(HorseID + "," + FoodName.getText() + "," + FoodQuantity.getText() + "," + FoodTime.getText());
    tPrinter.close(); 

    JOptionPane.showMessageDialog(null, "Nutritional data has been saved.","Info",JOptionPane.INFORMATION_MESSAGE); 


}
catch(Exception error) {
    System.out.println("Error in saving nutritional data");
}
   }

1 个答案:

答案 0 :(得分:1)

此行为是因为您将字符串数组传递给期望对象

export-csv

如果你想强制行为,那么你可以试试这个例子:

$c = @("dg","ert")                 
#you can replace the below variable with your $fulloutput                                                                               
$c| %{new-object psobject -property @{text=$_}} | Export-Csv test.csv  -NoTypeInformation                                              
notepad .\test.csv