在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
最满意答案
您可以将套接字设置为非阻塞模式或启用接收超时。 这是来自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.
相关问答
更多-
非阻塞TCP套接字在read()上连续接收EAGAIN(nonblocking TCP socket continuously receive EAGAIN on read())[2023-04-29]
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 ...