使用java和命令提示符写入文件(writing to a file using java and command prompt)
当我从命令提示符运行此命令
ffmpeg -i "C:\user\test.wmv" >C:\user\test.wmv_info.txt 2>&1
时它可以正常工作,但是当我尝试通过调用命令提示符它执行正常,但不写入文件。知道为什么吗?
我的java代码是:
public void getInfoThroughCommandLine(String sourceFilePath) { try { String infoFile = sourceFilePath+"_info.txt"; String command = "ffmpeg -i \"" + sourceFilePath +"\" >"+infoFile+" 2>&1"; // Execute the command Process process = Runtime.getRuntime().exec("cmd.exe /c start " + command); logger.info("Executing getInfoThroughCommandLine command: " + command); // Read the response BufferedReader input = new BufferedReader(new InputStreamReader( p.getInputStream())); BufferedReader error = new BufferedReader(new InputStreamReader( p.getErrorStream())); // Parse the input stream String line = input.readLine(); System.out.println("ffmpeg execution of: " + sourceFilePath); while (line != null) { System.out.println("\t***" + line); line = input.readLine(); } // Parse the error stream line = error.readLine(); System.out.println("Error Stream: " + sourceFilePath); while (line != null) { //do somthing } } catch (Exception e) { System.err.println(e); } }
when I run this command
ffmpeg -i "C:\user\test.wmv" >C:\user\test.wmv_info.txt 2>&1
from command prompt it works but when I try to the same from java file by calling the command prompt it executes all right but does not writes to the file.Any idea why?
my java code is:
public void getInfoThroughCommandLine(String sourceFilePath) { try { String infoFile = sourceFilePath+"_info.txt"; String command = "ffmpeg -i \"" + sourceFilePath +"\" >"+infoFile+" 2>&1"; // Execute the command Process process = Runtime.getRuntime().exec("cmd.exe /c start " + command); logger.info("Executing getInfoThroughCommandLine command: " + command); // Read the response BufferedReader input = new BufferedReader(new InputStreamReader( p.getInputStream())); BufferedReader error = new BufferedReader(new InputStreamReader( p.getErrorStream())); // Parse the input stream String line = input.readLine(); System.out.println("ffmpeg execution of: " + sourceFilePath); while (line != null) { System.out.println("\t***" + line); line = input.readLine(); } // Parse the error stream line = error.readLine(); System.out.println("Error Stream: " + sourceFilePath); while (line != null) { //do somthing } } catch (Exception e) { System.err.println(e); } }
原文:https://stackoverflow.com/questions/7838116
最满意答案
您是否尝试使用
\usepackage[unicode]{hyperref}
\hypersetup{ unicode = true }
,或者等效地在之后指定\hypersetup{ unicode = true }
? 这应该使您能够在书签中使用unicode字符。Have you tried loading hyperref using
\usepackage[unicode]{hyperref}
, or, equivalently, specifying\hypersetup{ unicode = true }
right after ? This should enable you to use unicode characters in bookmarks.
相关问答
更多-
为什么我的byte []得到HttpServletResponse编码的UTF-8?(Why my byte[] gets UTF-8 encoded by HttpServletResponse?)[2022-06-04]
代码有效! 一位同事下载了我的分支并运行了应用程序...下载的文件没问题。 因此,我尝试将代码传递给另一位同事,然后将其部署到测试服务器上,始终获得积极的结果。 问题必须在某些工作空间或机器设置中,但肯定不在代码中。 The code works! A colleague downloaded my branch and run the application... The downloaded file was ok. So I tried to pass the code to another coll ... -
如果使用Python 2.7或更高版本,请在传递给DictWriter之前,使用字典理解将字典重新映射为utf-8: # coding: utf-8 import csv D = {'name':u'马克','pinyin':u'mǎkè'} f = open('out.csv','wb') f.write(u'\ufeff'.encode('utf8')) # BOM (optional...Excel needs it to open UTF-8 file properly) w = csv.DictW ...
-
BOM将在less.js的下一版本中被删除 - 1.3.1。 您也可以在github源页面上试一试。 https://github.com/cloudhead/less.js/commit/6696368eb351824f33dc0aac67143d8ea80a085a The BOM will be stripped in the next version of less.js - 1.3.1. You can also try it out on the github source pages. htt ...
-
Java的UTF-8编码(Java's UTF-8 encoding)[2022-03-31]
您在第一个示例中正确编写了UTF-8(尽管您是从字符串冗余地创建字符串) 问题是您用于查看文件的查看器或工具不会将文件读取为UTF-8。 不要混合ASCII,只是将所有非ASCII字节转换为问号。 You're writing UTF-8 correctly in your first example (although you're redundantly creating a String from a String) The problem is that the viewer or tool you ... -
report类下的\maketitle在标题页上将页码设置为1 ,但也从1开始为下一页重新启动它。 这就是为什么你为标题获得虚拟页码1,然后是ToC的实际页码1。 我在这里强调虚拟 ,因为\maketitle在empty页面样式上设置标题,以便在页眉/页脚中不打印任何内容。 但是,在Adobe Acrobat中查看时,这些页码仍会显示在工具栏中。 其中一种方法是手动将页面显示更改为更适合标题页面的内容。 例如,让我们将标题页称为T : \documentclass{report} \usepackage{ ...
-
首先,不要依赖于mb_detect_encoding 。 除非有一堆编码特定实体(意味着在其他编码中无效的实体),否则在确定编码是什么方面并不是很好。 尝试一起摆脱mb_detect_encoding行。 哦, utf8_encode将Latin-1字符串转换为UTF-8字符串(不是从任意字符集到UTF-8 ,这是你真正想要的)...你想要iconv ,但你需要知道源编码(因为你不能真正信任mb_detect_encoding ,你需要通过其他方式来解决它。 或者你可以尝试使用带有空输入编码的$str = ...
-
您是否尝试使用\usepackage[unicode]{hyperref} \hypersetup{ unicode = true } ,或者等效地在之后指定\hypersetup{ unicode = true } ? 这应该使您能够在书签中使用unicode字符。 Have you tried loading hyperref using \usepackage[unicode]{hyperref}, or, equivalently, specifying \hypersetup{ unicode = ...
-
Scala编译器是否可以使用UTF-8编码的源文件?(Does the Scala compiler work with UTF-8 encoded source files?)[2022-05-23]
回答我自己的问题: scala编译器是否可以使用UTF-8编码文件? 是的,但前提是它知道它们是UTF-8编码的。 在没有任何其他证据的情况下,它使用Java的file.encoding属性。 (感谢@AndreasNeumann回答这部分内容。) 为什么我的程序不符合我的预期? 因为我的file.encoding属性被设置为MacRoman 。 尽管我告诉eclipse该文件是UTF-8,但这些信息并未传达给Scala编译器。 因此,根据MacRoman编码,编译器将3字节序列E2 89 A4解释为三字符 ... -
C中的UTF-16到UTF-8(UTF-16 to UTF-8 in C)[2023-04-14]
如果您使用的是* nix系统,则可以使用iconv 示例: iconv -f UTF16 -t UTF8 file.csv If you are on a *nix system you can use iconv Example: iconv -f UTF16 -t UTF8 file.csv -
好的,这是你的问题: utf_8 [\x0000-\xffff]* bom [\xEF\xBB\xBF] 这里有两个问题。 首先,Flex实际上并不了解Unicode。 它适用于字节 。 所以你需要一个匹配任何有效的UTF-8 字节序列的正则表达式宏。 http://keithdevens.com/weblog/archive/2004/Jun/29/UTF-8.regex有一个正则表达式可以做到这一点,转换为Flex语法并不是很难(见下文)。 其次,BOM宏中的方括号使其匹配 ...