C:\user\"/>
首页 \ 问答 \ 使用java和命令提示符写入文件(writing to a file using java and command prompt)

使用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
更新时间:2023-07-25 12:07

最满意答案

您是否尝试使用\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.

相关问答

更多
  • 代码有效! 一位同事下载了我的分支并运行了应用程序...下载的文件没问题。 因此,我尝试将代码传递给另一位同事,然后将其部署到测试服务器上,始终获得积极的结果。 问题必须在某些工作空间或机器设置中,但肯定不在代码中。 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 ...
  • 您在第一个示例中正确编写了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编码文件? 是的,但前提是它知道它们是UTF-8编码的。 在没有任何其他证据的情况下,它使用Java的file.encoding属性。 (感谢@AndreasNeumann回答这部分内容。) 为什么我的程序不符合我的预期? 因为我的file.encoding属性被设置为MacRoman 。 尽管我告诉eclipse该文件是UTF-8,但这些信息并未传达给Scala编译器。 因此,根据MacRoman编码,编译器将3字节序列E2 89 A4解释为三字符 ...
  • 如果您使用的是* 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宏中的方括号使其匹配 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)