首页 \ 问答 \ 在java中执行批处理文件会产生意外结果(Executing Batch file in java gives unexpected results)

在java中执行批处理文件会产生意外结果(Executing Batch file in java gives unexpected results)

我有以下批文件: -

gcc temp.c -o temp.exe
pause

此批处理文件编译.c文件。 通过双击执行此批处理脚本运行正常,但是当我为此目的使用java时,它给了我一个错误。 以下是代码

Process p = Runtime.getRuntime().exec("cmd /c start CPrun.bat");
p.waitFor();

CRun.bat是批处理文件的名称。

以下是cmd上的错误

'gcc' is not recognized as an internal or external command, 
operable program or batch file.

请注意,gcc是我的C编译器,它在我的计算机的路径中定义


I have the following batch File : -

gcc temp.c -o temp.exe
pause

This batch file compiles a .c file. This batch script runs fine when executed by double clicking, but When I use java for that purpose, It gives me an error. The following is the code

Process p = Runtime.getRuntime().exec("cmd /c start CPrun.bat");
p.waitFor();

CRun.bat is the name of the batch file.

The following is the error on cmd

'gcc' is not recognized as an internal or external command, 
operable program or batch file.

Note that gcc is my Compiler for C which is defined in the path of my Computer


原文:https://stackoverflow.com/questions/41185728
更新时间:2022-04-17 10:04

最满意答案

您可以将套接字设置为非阻塞模式或启用接收超时。 这是来自mac上的recv(2)

The calls fail if:
[EAGAIN] The socket is marked non-blocking, and the receive operation would block, or a receive timeout had been set, and the timeout expired before data were received.

编辑0:

嗯,再次引用道歉。 这次是从intro(2)

11 EDEADLK Resource deadlock avoided. An attempt was made to lock a system resource that would have resulted in a deadlock situation.
...
35 EAGAIN Resource temporarily unavailable. This is a temporary condition and later calls to the same routine may complete normally.

只需使用strerror(3)来找出实际问题。


You either set the socket to non-blocking mode or enabled the receive timeout. Here's from recv(2) on a mac:

The calls fail if:
[EAGAIN] The socket is marked non-blocking, and the receive operation would block, or a receive timeout had been set, and the timeout expired before data were received.

Edit 0:

Hmm, apologies for quoting again. This time from intro(2):

11 EDEADLK Resource deadlock avoided. An attempt was made to lock a system resource that would have resulted in a deadlock situation.
...
35 EAGAIN Resource temporarily unavailable. This is a temporary condition and later calls to the same routine may complete normally.

Just use strerror(3) to figure out the actual issue.

相关问答

更多
  • read()应返回n = 0,以便在读取网页中的所有内容后停止while循环。 不,不应该。 当对等体关闭连接时,它应该返回零。 您是HTTP keep-alive的受害者。 如果您不想这样,请发送标题Connection: close 。 否则,您需要读取所有标头,然后从Content-length标头获取主体大小,并准确读取那么多字节。 请注意,以这种方式使用非阻塞套接字完全没有意义。 你的睡眠时间太短或太长。 阻塞模式recv()或read()阻塞了恰当的时间长度,它是一行代码。 如果需要套接字超时, ...
  • 答案是隐藏在你的windows标签中(感谢包含它 )。 相关: http : //api.zeromq.org/4-1 : zmq-errno 特别: 提供zmq_errno()函数是为了帮助非POSIX系统上的用户直接检索正确的errno值时遇到问题。 具体来说,Win32系统上的应用程序使用来自ØMQ使用的C运行时库的不同C运行时库的用户将需要使用zmq_errno()来进行正确操作。 您应该使用zmq_errno()而不是直接访问errno 。 The answer is hiding in your ...
  • 标准malloc()在失败时不会将errno设置为EAGAIN 。 在Unix下, malloc()很可能将errno设置为ENOMEM 。 通常,errno EAGAIN表示Resource temporarily unavailable 。 这意味着操作系统可能在一段时间内拥有可用资源。 这只是一种说法, 我现在没有足够的记忆,但我会尝试在最近的将来释放一些,然后我可以给你 。 这可能与操作系统通常为进程分配内存的方式有关 - 即使内存是free()'d它也不会返回操作系统,但仍然为该进程保留。 我只是 ...
  • 第1步:做一个简单的测试: 那么,作为最低要求,应该首先进行这种测试 - 排队: rc = zmq_send ( req_socket, "A_TEST_BLOCK", 12, ZMQ_DONTWAIT ); printf ( "INF: zmq_send ( req_socket, "A_TEST_BLOCK", 12, ZMQ_DONTWAIT )\nZMQ: returned rc == %d\nZMQ: zmq_errno ~ %s\n", rc, ...
  • 从Linux的select手册页 : 在Linux下,select()可以将套接字文件描述符报告为“准备好读取”,而不是后续的读取块。 例如,这可能发生在数据到达但是经过检查时 有错误的校验和,并被丢弃。 可能存在其他情况,其中虚假地报告文件描述符为就绪。 因此,在不应阻塞的套接字上使用O_NONBLOCK可能更安全。 当然,这个警告是在错误部分,暗示作者认为这不是预期的行为 - 但是,在Linux下,至少它是可能发生的事情。 就个人而言,我总是将我的插座设置为非阻塞; 这样我就不必担心我的程序会意外阻塞除 ...
  • EAGAIN并不意味着你断开连接,它只是意味着“现在没有什么可读的,以后再试一次”。 您可以使用fcntl(2)取消设置O_NONBLOCK (使read等待,直到有可用的东西),或者在调用read之前,用select(2)之类的东西等待套接字。 编辑:现在你已经添加了更多的代码,我可以看到你正在为套接字设置SO_RCVTIMEO 。 这可能导致阻塞read返回EAGAIN (因此,如果您不希望发生这种情况,只需单独离开SO_RCVTIMEO )。 EAGAIN does not mean you're d ...
  • 您可以将套接字设置为非阻塞模式或启用接收超时。 这是来自mac上的recv(2) : The calls fail if: [EAGAIN] The socket is marked non-blocking, and the receive operation would block, or a receive timeout had been set, and the timeout expired before data were received. 编辑0: 嗯,再次引用道歉。 这次是从intro( ...
  • 如果套接字具有超时SO_RCVTIMEO选项设置(默认为0),它也可能发生阻塞套接字和阻塞recv。 顺便说一下,你在recv()之前考虑过select()吗? It may also happen to blocking socket and blocking recv, if socket has timeout SO_RCVTIMEO option set (default is 0). BTW, did you consider select() before recv()?
  • 您希望shutdown(fd, SHUT_WR)仅关闭写入但仍能够读取。 close(fd)将使文件描述符无效,就像关闭了本地文件的开放路径一样。 http://man7.org/linux/man-pages/man2/shutdown.2.html You want shutdown(fd, SHUT_WR) to close only for writes but still be able to read. close(fd) will invalidate the file descriptor ...
  • 您的mlockall()调用要求锁定所有将来的内存分配。 但是,操作系统设置了可由任何一个非特权进程锁定的最大内存量。 您可以使用getrlimit(RLIMIT_MEMLOCK,...)查询此金额。 在我的系统上它是65536字节。 现在,当我在我的系统上运行程序时,使用strace(1)查看进行了哪些系统调用,我得到以下结果: mlockall(MCL_FUTURE) = 0 brk(0) = 0x2 ...

相关文章

更多

最新问答

更多
  • 您如何使用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)